Skip to content

Instantly share code, notes, and snippets.

@jubishop
Created January 27, 2009 23:51
Show Gist options
  • Save jubishop/53673 to your computer and use it in GitHub Desktop.
Save jubishop/53673 to your computer and use it in GitHub Desktop.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:facebook="com.pbking.facebook.*"
creationComplete="creationComplete()">
<mx:Script><![CDATA[
import flash.events.Event;
import mx.events.CloseEvent;
import mx.controls.Alert;
import com.pbking.facebook.Facebook;
import com.pbking.facebook.events.FacebookActionEvent;
import com.pbking.facebook.session.DesktopSession;
import com.pbking.facebook.commands.friends.GetFriends;
[Bindable]
private var facebook:Facebook;
private var desktopSession:DesktopSession;
private var api_key:String =
'9c428463e48a0d041b81aa14409d21a8';
private var application_secret:String =
'7d21e79a5260ce9e75f7fa303dd5e173';
private function creationComplete():void
{
// We establish a desktop session, providing the api-key and secret-key
// for our app. These are for a demo app called quikvote, please
// replace with your own.
desktopSession = new DesktopSession(api_key, application_secret);
// This is our generic facebook object that handles sessions
facebook = new Facebook();
// Ok we're going to listen for callbacks on logging in and connecting
facebook.addEventListener(FacebookActionEvent.WAITING_FOR_LOGIN,
waiting_for_login);
facebook.addEventListener(FacebookActionEvent.CONNECT,
connected);
// Start our desktop session
facebook.startSession(desktopSession);
}
// So this gets called when we've popped open a browser window
// and prompted our user to log in. It'll use the built in session
// cookie if it exists. This is proper oauthing for desktop apps.
private function waiting_for_login(event:FacebookActionEvent):void {
// Note, this alert triggers logged_in when it's dismissed...
Alert.show("A Facebook login prompt is opening in a browser window. Login and when instructed close that window and click 'OK'.", "Facebook Login", Alert.OK, null, logged_in);
}
// Once the user has logged in via the website then we validate our
// desktop session here
private function logged_in(event:CloseEvent):void
{
facebook.validateDesktopSession();
}
// At this point we're fully authorized. You can pop open your
// screensaver or do whatever. You're authenticated.
private function connected(event:FacebookActionEvent):void {
// Just to demo that we've logged in as ourself, we pop-up our user id
// that logged into facebook via the browser popup before.
Alert.show("My id is: " + desktopSession.uid);
// Show some data about our session, this could be infinite soon.
// expires would be 0 if infinite.
Alert.show("Session expires: " + desktopSession.expires);
Alert.show("Session key: " + desktopSession.session_key);
}
]]></mx:Script>
</mx:Application>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment