2007-04-27 Thomas Van Machelen <thomas.vanmachelen@gmail.com>
* src/Mono.Facebook/FacebookSession: add an extra constructor to restart an infinite session and return the SessionInfo on GetSession if it's an infinite one * src/Mono.Facebook/Responses: add the expires attribute on SessionInfo so we can check for infinite sessions and add an extra constructor to restore the infinite session * examples/Makefile.am: * examples/InfiniteSession.cs: a new example to demonstrate the use of infinite sessions svn path=/trunk/facebook-sharp/; revision=76369
This commit is contained in:
Родитель
b1b11c26ea
Коммит
47eabfdd63
12
ChangeLog
12
ChangeLog
|
@ -1,3 +1,15 @@
|
|||
2007-04-27 Thomas Van Machelen <thomas.vanmachelen@gmail.com>
|
||||
* src/Mono.Facebook/FacebookSession:
|
||||
add an extra constructor to restart an infinite session and
|
||||
return the SessionInfo on GetSession if it's an infinite one
|
||||
* src/Mono.Facebook/Responses:
|
||||
add the expires attribute on SessionInfo so we can check for
|
||||
infinite sessions and add an extra constructor to restore the
|
||||
infinite session
|
||||
* examples/Makefile.am:
|
||||
* examples/InfiniteSession.cs:
|
||||
a new example to demonstrate the use of infinite sessions
|
||||
|
||||
2007-04-09 George Talusan <george@convolve.ca>
|
||||
* src/Mono.Facebook/User.cs:
|
||||
cover user information better
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
using System;
|
||||
using Mono.Facebook;
|
||||
|
||||
namespace Mono.Facebook.Test
|
||||
{
|
||||
class GetAlbums
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// create session
|
||||
FacebookSession session = new FacebookSession("ca9511b32569d823f1d3a942b31c6c84", "61f4712317fb7a2d12581f523c01fe71");
|
||||
|
||||
// create token and login with it
|
||||
Uri login = session.CreateToken();
|
||||
System.Diagnostics.Process.Start("firefox", login.AbsoluteUri);
|
||||
Console.WriteLine ("Press enter after you've logged in.");
|
||||
Console.ReadLine ();
|
||||
|
||||
// get session key
|
||||
SessionInfo old_info = session.GetSession();
|
||||
|
||||
// check for infinite
|
||||
if (old_info == null) {
|
||||
Console.WriteLine ("Not an infinite session... quitting.");
|
||||
return;
|
||||
}
|
||||
|
||||
Console.WriteLine ("Infinite Session: session key {0} secret {1}",
|
||||
old_info.SessionKey, old_info.Secret);
|
||||
|
||||
Console.WriteLine ("Press enter after you've logged out.");
|
||||
Console.ReadLine ();
|
||||
|
||||
SessionInfo new_info = new SessionInfo (old_info.SessionKey, old_info.UId, old_info.Secret);
|
||||
session = new FacebookSession ("ca9511b32569d823f1d3a942b31c6c84", new_info);
|
||||
|
||||
foreach (Album a in session.GetAlbums ())
|
||||
Console.WriteLine (a.Name);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
SAMPLES=GetAlbums.cs GetFriends.cs GetEvents.cs
|
||||
SAMPLES=GetAlbums.cs GetFriends.cs GetEvents.cs InfiniteSession.cs
|
||||
MCSFLAGS= -debug -nologo -r:Mono.Facebook.dll
|
||||
|
||||
EXTRA_DIST=$(SAMPLES)
|
||||
|
|
|
@ -52,11 +52,19 @@ namespace Mono.Facebook
|
|||
get { return session_info.SessionKey; }
|
||||
}
|
||||
|
||||
// use this for plain sessions
|
||||
public FacebookSession (string api_key, string shared_secret)
|
||||
{
|
||||
util = new Util (api_key, shared_secret);
|
||||
}
|
||||
|
||||
// use this if you want to re-start an infinite session
|
||||
public FacebookSession (string api_key, SessionInfo session_info)
|
||||
: this (api_key, session_info.Secret)
|
||||
{
|
||||
this.session_info = session_info;
|
||||
}
|
||||
|
||||
public Uri CreateToken ()
|
||||
{
|
||||
XmlDocument doc = util.GetResponse ("facebook.auth.createToken");
|
||||
|
@ -65,12 +73,15 @@ namespace Mono.Facebook
|
|||
return new Uri (string.Format ("http://www.facebook.com/login.php?api_key={0}&v=1.0&auth_token={1}", util.ApiKey, auth_token));
|
||||
}
|
||||
|
||||
public void GetSession ()
|
||||
public SessionInfo GetSession ()
|
||||
{
|
||||
this.session_info = util.GetResponse<SessionInfo> ("facebook.auth.getSession",
|
||||
FacebookParam.Create ("auth_token", auth_token));
|
||||
this.util.SharedSecret = session_info.Secret;
|
||||
|
||||
this.auth_token = string.Empty;
|
||||
|
||||
return session_info.IsInfinite ? session_info : null;
|
||||
}
|
||||
|
||||
public Album[] GetAlbums ()
|
||||
|
|
|
@ -42,6 +42,28 @@ namespace Mono.Facebook
|
|||
|
||||
[XmlElement ("secret")]
|
||||
public string Secret;
|
||||
|
||||
[XmlElement ("expires")]
|
||||
public long Expires;
|
||||
|
||||
[XmlIgnore ()]
|
||||
public bool IsInfinite
|
||||
{
|
||||
get { return Expires == 0; }
|
||||
}
|
||||
|
||||
public SessionInfo ()
|
||||
{}
|
||||
|
||||
// use this if you want to create a session based on infinite session
|
||||
// credentials
|
||||
public SessionInfo (string session_key, long uid, string secret)
|
||||
{
|
||||
this.SessionKey = session_key;
|
||||
this.UId = uid;
|
||||
this.Secret = secret;
|
||||
this.Expires = 0;
|
||||
}
|
||||
}
|
||||
|
||||
[XmlRoot ("photos_getAlbums_response", Namespace = "http://api.facebook.com/1.0/", IsNullable = false)]
|
||||
|
|
Загрузка…
Ссылка в новой задаче