Posted By

chrisaiv on 04/19/09


Tagged

Flex facebook


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

davidsi


Flex: My First Flex / Facebook Application


 / Published in: MXML
 

URL: http://www.adobe.com/devnet/facebook/articles/video_facebook_quick_start.html

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
  3. <mx:Script>
  4. <![CDATA[
  5. import com.facebook.data.users.FacebookUser;
  6. import com.facebook.data.users.GetInfoData;
  7. import com.facebook.data.users.GetInfoFieldValues;
  8. import com.facebook.commands.users.GetInfo;
  9. import com.facebook.net.FacebookCall;
  10. import mx.controls.Alert;
  11. import com.facebook.utils.FacebookSessionUtil;
  12. import com.facebook.events.FacebookEvent;
  13.  
  14. //If you are external, you need to launch a browser window so that a user can log-in
  15. public var fbSession:FacebookSessionUtil;
  16.  
  17. private var fbApiKey:String;
  18. private var fbSecret:String;
  19. private var fbLoaderInfo:LoaderInfo;
  20.  
  21. private function fbLogin():void
  22. {
  23. fbApiKey = "API_KEY";
  24. fbSecret = "SECRET";
  25. fbLoaderInfo = stage.loaderInfo;
  26.  
  27. //The user is going to the Log-in page
  28. fbSession = new FacebookSessionUtil( fbApiKey, fbSecret, fbLoaderInfo);
  29. fbSession.addEventListener( FacebookEvent.WAITING_FOR_LOGIN, fbWaitingForLoginHandler, false, 0, true );
  30. fbSession.addEventListener( FacebookEvent.CONNECT, fbConnectHandler, false, 0, true );
  31. fbSession.login();
  32. }
  33.  
  34. private function fbWaitingForLoginHandler( e:FacebookEvent ):void
  35. {
  36. //The user has returned from the log-in page and are now clicking "OK"
  37. var alert:Alert = Alert.show( "Click Ok after you've logged in", "Logging In" );
  38. alert.addEventListener( Event.CLOSE, alertCloseHandler );
  39. }
  40.  
  41. private function alertCloseHandler( e:Event ):void
  42. {
  43. //Verify that the user has logged in
  44. fbSession.validateLogin();
  45.  
  46. }
  47.  
  48. private function fbConnectHandler( e:FacebookEvent ):void
  49. {
  50. //Get the Information for the Logged-in user through Facebook Calls
  51. //FacebookCall is using the POST Method on the Facebook Session
  52. //new GetInfo( [Current User ID], [Field Names] )
  53. // var getInfo:GetInfo = new GetInfo( new Array( fbSession.facebook.uid ), new Array( 'name', 'pic_square', 'activities', 'interests' ) );
  54. var getInfo:GetInfo = new GetInfo( new Array( fbSession.facebook.uid), new Array( GetInfoFieldValues.ALL_VALUES ) );
  55.  
  56. var fbCall:FacebookCall = fbSession.facebook.post( getInfo );
  57. fbCall.addEventListener( FacebookEvent.COMPLETE, fbGetInfoCompleteHandler, false, 0, true );
  58. }
  59.  
  60. private function fbGetInfoCompleteHandler( e:FacebookEvent ):void
  61. {
  62. var getInfoData:GetInfoData = e.data as GetInfoData;
  63. var fbUser:FacebookUser = getInfoData.userCollection.getItemAt( 0 ) as FacebookUser;
  64. //Set the Image and Label to use that Data
  65. userAvatar.source = fbUser.pic_square;
  66. userName.text = fbUser.name;
  67. userActivities.text = fbUser.activities;
  68. userInterests.text = fbUser.interests;
  69. }
  70. ]]>
  71. </mx:Script>
  72. <mx:Button x="10" y="10" label="Login" click="fbLogin()"/>
  73.  
  74. <mx:Image x="83" y="10" width="80" height="80" id="userAvatar"/>
  75. <mx:Label x="178" y="12" text="Label" id="userName"/>
  76.  
  77. <mx:Label x="178" y="52" text="Interests"/>
  78. <mx:TextArea x="178" y="69" width="449" id="userInterests"/>
  79.  
  80. <mx:Label x="178" y="131" text="Activities"/>
  81. <mx:TextArea x="178" y="148" width="449" id="userActivities"/>
  82.  
  83. </mx:Application>

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: chona on March 1, 2011

hiii guys

You need to login to post a comment.