/ Published in: ActionScript 3
URL: http://www.adobe.com/devnet/facebook/samples/index.html#albumlist
This is pretty much Adobe's Sample #2 with a few nice improvements
Expand |
Embed | Plain Text
<?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" applicationComplete="initApp()"> <mx:Script> <![CDATA[ import mx.controls.Alert; import com.facebook.data.photos.GetAlbumsData; import com.facebook.commands.photos.GetAlbums; import com.facebook.net.FacebookCall; import com.facebook.Facebook; import com.facebook.events.FacebookEvent; import flash.display.Stage; import flash.display.LoaderInfo; import com.facebook.utils.FacebookSessionUtil; import mx.collections.ArrayCollection; private var API_KEY:String = "API_KEY"; private var SECRET_KEY:String = "SECRET_KEY"; private var fbook:Facebook; private var fbLoaderInfo:LoaderInfo; private var fbSession:FacebookSessionUtil; [Bindable] private var fbPhotoAlbums:ArrayCollection; private var currentMethod:Function; private function initApp():void { fbLoaderInfo = stage.loaderInfo; fbPhotoAlbums = new ArrayCollection(); } private function fbLogin():void { fbSession = new FacebookSessionUtil( API_KEY, SECRET_KEY, loaderInfo ); fbSession.addEventListener( FacebookEvent.WAITING_FOR_LOGIN, fbWaitingForLoginHandler, false, 0, true ); fbSession.addEventListener( FacebookEvent.CONNECT, fbOnConnectHandler, false, 0, true ); fbook = fbSession.facebook; fbSession.login(); } private function updateStatus( message:String ):void { fbStatus.text = message; } private function isAuthenticated( method:Function ):Boolean { //Store which method the current user is on currentMethod = method; //If a FacebookSession has not been created or user is not authenticated, Force a Login() if( fbSession == null || !fbSession.facebook.is_connected ){ fbLogin(); return false; } return true; } /************************************** * Facebook POST Request **************************************/ private function getPhotoAlbums():void { //Once Authentication has been solved, continue with the user's process if( isAuthenticated( arguments.callee ) ){ var call:FacebookCall = fbook.post( new GetAlbums( fbook.uid ) ); call.addEventListener( FacebookEvent.COMPLETE, photoAlbumsCompleteHandler, false, 0, true ); } } /************************************** * Facebook Event Handlers **************************************/ private function fbOnConnectHandler( e:FacebookEvent ):void { updateStatus( "You are logged into Facebook" ); //Continue where the user last left off before requiring Authentication currentMethod(); } 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 fbValidateLogin( ):void { fbSession.validateLogin(); } private function alertCloseHandler( e:Event ):void { //Verify that the user has logged in fbValidateLogin(); } private function photoAlbumsCompleteHandler( e:FacebookEvent ):void { var albumsResponseData:GetAlbumsData = e.data as GetAlbumsData; if( !albumsResponseData || e.error ){ trace( "photoAlbumsCompleteHandler: " + e.error ); updateStatus( "There was an error with collecting photo albums" ); return } //Iterate through the albumsResponseData.albumCollection to get the titles for( var i:uint = 0; i < albumsResponseData.albumCollection.length; i++ ){ fbPhotoAlbums.addItem( albumsResponseData.albumCollection.getItemAt( i ) ); } } ]]> </mx:Script> <mx:Button label="Get Photo Albums" click="getPhotoAlbums()" x="10" y="10"/> <mx:Label text="Status" color="0xFFFF00" fontWeight="bold" fontSize="14" x="162" y="8"/> <mx:Text id="fbStatus" text="Please Log In" x="223" y="11" /> <mx:DataGrid dataProvider="{fbPhotoAlbums}" width="50%" y="72" x="10"> <mx:columns> <mx:DataGridColumn headerText="Album Name" dataField="name" /> <mx:DataGridColumn headerText="Date" dataField="created" /> </mx:columns> </mx:DataGrid> </mx:Application>
Comments
Subscribe to comments
You need to login to post a comment.

hi, I try the sample "Flex: Get Photo Albums in Facebook" When I run it I can login, but when I "click" Get Photo Albums not display nothing just the DataGrid empty. Whit the Safari I look at activity and it show "http://api.facebook.com/restserver.php"
Can you tell me why or where is my problem?
Thanks,
Bob
hi, I try the sample "Flex: Get Photo Albums in Facebook" When I run it I can login, but when I "click" Get Photo Albums not display nothing just the DataGrid empty. Whit the Safari I look at activity and it show "http://api.facebook.com/restserver.php"
Can you tell me why or where is my problem?
Thanks,
Bob