// Note: Make sure the MonoTest application is logged out // in your facebook account before you run this test static void Main(string[] args) { // create session FacebookSession session = new FacebookSession("ca9511b32569d823f1d3a942b31c6c84", "61f4712317fb7a2d12581f523c01fe71"); // create token and login with it Uri login = session.GetUriForInfiniteToken (); System.Diagnostics.Process.Start ("firefox", login.AbsoluteUri); Console.Write ("Paste the generated token here: "); string token = Console.ReadLine (); // get session key SessionInfo old_info = session.GetSessionFromToken (token); // check for infinite if (!old_info.IsInfinite) { Console.WriteLine ("Not an infinite session... quitting."); return; } Console.WriteLine ("Infinite Session: session key {0} secret {1}", old_info.SessionKey, old_info.Secret); // logout Console.WriteLine ("Press enter after you've logged out."); Console.ReadLine (); // log in again with infinite session key SessionInfo new_info = new SessionInfo (old_info.SessionKey, old_info.UId, old_info.Secret); session = new FacebookSession ("ca9511b32569d823f1d3a942b31c6c84", new_info); // prove by getting albums foreach (Album a in session.GetAlbums ()) Console.WriteLine (a.Name); }
// 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 SessionInfo GetSessionFromToken(string auth_token) { 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; }
bool SaveSessionInfo(SessionInfo info) { string keyring; try { keyring = Ring.GetDefaultKeyring(); } catch (KeyringException e) { Log.DebugException (e); return false; } Hashtable attribs = new Hashtable(); attribs["name"] = keyring_item_name; attribs["uid"] = info.uid.ToString (); attribs["session_key"] = info.session_key; try { Ring.CreateItem (keyring, ItemType.GenericSecret, keyring_item_name, attribs, info.secret, true); } catch (KeyringException e) { Log.DebugException (e); return false; } return true; }
SessionInfo ReadSessionInfo() { SessionInfo info = null; Hashtable request_attributes = new Hashtable (); request_attributes["name"] = keyring_item_name; try { foreach (ItemData result in Ring.Find (ItemType.GenericSecret, request_attributes)) { if (!result.Attributes.ContainsKey ("name") || !result.Attributes.ContainsKey ("uid") || !result.Attributes.ContainsKey ("session_key") || (result.Attributes["name"] as string) != keyring_item_name) continue; string session_key = (string)result.Attributes["session_key"]; long uid = Int64.Parse((string)result.Attributes["uid"]); string secret = result.Secret; info = new SessionInfo (session_key, uid, secret); break; } } catch (KeyringException e) { Log.DebugException (e); } return info; }