/ Published in: MXML

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Script> <![CDATA[ import com.facebook.data.users.FacebookUser; import com.facebook.data.users.GetInfoData; import com.facebook.data.users.GetInfoFieldValues; import com.facebook.commands.users.GetInfo; import com.facebook.net.FacebookCall; import mx.controls.Alert; import com.facebook.utils.FacebookSessionUtil; import com.facebook.events.FacebookEvent; //If you are external, you need to launch a browser window so that a user can log-in public var fbSession:FacebookSessionUtil; private var fbApiKey:String; private var fbSecret:String; private var fbLoaderInfo:LoaderInfo; private function fbLogin():void { fbApiKey = "API_KEY"; fbSecret = "SECRET"; fbLoaderInfo = stage.loaderInfo; //The user is going to the Log-in page fbSession = new FacebookSessionUtil( fbApiKey, fbSecret, fbLoaderInfo); fbSession.addEventListener( FacebookEvent.WAITING_FOR_LOGIN, fbWaitingForLoginHandler, false, 0, true ); fbSession.addEventListener( FacebookEvent.CONNECT, fbConnectHandler, false, 0, true ); fbSession.login(); } private function fbWaitingForLoginHandler( e:FacebookEvent ):void { //The user has returned from the log-in page and are now clicking "OK" var alert:Alert = Alert.show( "Click Ok after you've logged in", "Logging In" ); alert.addEventListener( Event.CLOSE, alertCloseHandler ); } private function alertCloseHandler( e:Event ):void { //Verify that the user has logged in fbSession.validateLogin(); } private function fbConnectHandler( e:FacebookEvent ):void { //Get the Information for the Logged-in user through Facebook Calls //FacebookCall is using the POST Method on the Facebook Session //new GetInfo( [Current User ID], [Field Names] ) // var getInfo:GetInfo = new GetInfo( new Array( fbSession.facebook.uid ), new Array( 'name', 'pic_square', 'activities', 'interests' ) ); var getInfo:GetInfo = new GetInfo( new Array( fbSession.facebook.uid), new Array( GetInfoFieldValues.ALL_VALUES ) ); var fbCall:FacebookCall = fbSession.facebook.post( getInfo ); fbCall.addEventListener( FacebookEvent.COMPLETE, fbGetInfoCompleteHandler, false, 0, true ); } private function fbGetInfoCompleteHandler( e:FacebookEvent ):void { var getInfoData:GetInfoData = e.data as GetInfoData; var fbUser:FacebookUser = getInfoData.userCollection.getItemAt( 0 ) as FacebookUser; //Set the Image and Label to use that Data userAvatar.source = fbUser.pic_square; userName.text = fbUser.name; userActivities.text = fbUser.activities; userInterests.text = fbUser.interests; } ]]> </mx:Script> <mx:Button x="10" y="10" label="Login" click="fbLogin()"/> <mx:Image x="83" y="10" width="80" height="80" id="userAvatar"/> <mx:Label x="178" y="12" text="Label" id="userName"/> <mx:Label x="178" y="52" text="Interests"/> <mx:TextArea x="178" y="69" width="449" id="userInterests"/> <mx:Label x="178" y="131" text="Activities"/> <mx:TextArea x="178" y="148" width="449" id="userActivities"/> </mx:Application>
URL: http://www.adobe.com/devnet/facebook/articles/video_facebook_quick_start.html
Comments
