Shandan Spencer
Shandan Spencer

Reputation: 1

Getting friends list for Facebook Mobile application using Flash builder

This is what I want to happen:

  1. Get list of the users friends
  2. Display them in any kind of container.

I go to look at the graph API documentation, but that doesn't really help me given the fact that I am a visual learner. To get that basic functions of the Mobile Application, I followed tutorials that left me at a cliff hanger as far as implementing other more complex features into the Application.

I will list the links to the Mobile a Application here: Part 1, Part 2. Those tutorials helped me a lot. But when they were over and I had to start implementing features my self, I was kind of left at a standstill. I've been searching and searching for how to do this, but could not really find anything that helped since they were all for Desktop Applications. I've also looked at the sample code that the Facebook API supplies for reference. But none is for flex Mobile, and it also seems that you'd have to write your code exactly like theirs to get those features to work properly. Alright. So once again, I just want to be able to have a list of friends to show up. I will worry about getting details of the friends later. I think I might be able to manage that. Also, I am going to post all of my code because I am in no way protective of it right now. I will state one thing though. In NO way am I asking for someone to write the code for me. I am just a very visual dependent learner. But I think if I can get the process of implementing features explained in a more simpler manor, I would be able to take care of my own. Which also brings up another question. Since I am a Visual Person. Would using flash instead of Flash Builder be more suitable for me?

Here is the code:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           applicationDPI="160" creationComplete="application1_creationCompleteHandler(event)"
           currentState="loggedout"
           width.loggedin="392" height.loggedin="442">
<fx:Style source="beta.css"/>
<fx:Script>
    <![CDATA[
        import com.facebook.graph.FacebookMobile;
        import com.facebook.graph.controls.Distractor;
        import com.facebook.graph.core.FacebookURLDefaults;
        import com.facebook.graph.data.Batch;
        import com.facebook.graph.net.FacebookRequest;
        import com.facebook.graph.utils.FacebookDataUtils;
        
        import mx.collections.ArrayList;
        import mx.core.UIComponent;
        import mx.events.FlexEvent;
        
        
        public var permissions:Array = ["user_photos","user_birthday","read_stream","publish_stream","read_friendslists","manage_friendslist"]; 
        protected function application1_creationCompleteHandler(event:FlexEvent):void
        {
            FacebookMobile.init("APP_ID", onLogin)
        }
    
        protected function submitPost():void
        {
            FacebookMobile.api("/me/feed",submitPostHandler,{message:statusInput.text}, "POST");
        }
        
        protected function submitPostHandler(result:Object,fail:Object):void
        {
            statusInput.text="";
            FacebookMobile.api("/me/statuses",getStatusHandler);
        }
        
        protected function getStatusHandler(postsuccess:Object, fail:Object):void
        {
            lblStatus.text=postsuccess[0].message;
        }

        
        protected function login():void{
            var facebookWebView:StageWebView = new StageWebView();
            facebookWebView.viewPort = new Rectangle(0,0,stage.width, stage.height-100);
            FacebookMobile.login(onLogin, this.stage,permissions, facebookWebView);
        }
        
        protected function onLogin(success:Object, fail:Object):void{
            if(success){
                currentState="loggedin";
                nameLbl.text=success.user.name;
                imgUser.source=FacebookMobile.getImageUrl(success.uid,"small");
                birthdayLbl.text=success.user.birthday;
                FacebookMobile.api("me/statuses",getStatusHandler);
            }
        }
        
    ]]>
</fx:Script>

<s:states>
    <s:State name="loggedin"/>
    <s:State name="loggedout"/>
</s:states>
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:Button id="loginoutBtn" x="244" y="13" label="Log In"
          x.loggedin="228" y.loggedin="10" label.loggedin="Log out"
          click.loggedout="login()"/>
<s:Label id="nameLbl" includeIn="loggedin" x="67" y="11" width="97" height="43"/>
<s:Image id="imgUser" includeIn="loggedin" x="8" y="9" width="50"/>
<s:Label id="birthdayLbl" includeIn="loggedin" x="66" y="86" width="96"/>
<s:Label id="lblStatus" includeIn="loggedin" x="10" y="135" width="154" height="58" />
<s:TextInput id="statusInput" includeIn="loggedin" x="10" y="230" height="40"/>
<s:Button includeIn="loggedin" x="172" y="278" width="115" height="32" label="Submit"
          click="submitPost()"/>

<s:Button x="10" y="147" width="157" label="Post photo" includeIn="loggedin"
          x.loggedin="10" y.loggedin="278" width.loggedin="113" height.loggedin="32"/>
<s:List includeIn="loggedin" x="170" y="61" width="212" height="161" itemRenderer="friendsRender"></s:List>
</s:Application>

Upvotes: 0

Views: 1334

Answers (2)

Tan Vu
Tan Vu

Reputation: 1

Please download Graph API 1.8.1 Examples:

http://code.google.com/p/facebook-actionscript-api/downloads/detail?name=GraphAPI_Examples_1_8_1.zip

It is have:

FriendsList_flash

FriendsList_flex

FriendsListMobile_Flash

http://code.google.com/p/facebook-actionscript-api/source/browse/trunk/examples/?r=342

Upvotes: 0

Christopher Nassar
Christopher Nassar

Reputation: 554

Supposing that you have facebook mobile for as3, you can use the following function:

FacebookMobile.api("/me/friends",onApiCallFriends);

protected function onApiCallFriends(response:Object, fail:Object):void
{
if (response)
{   
      var friends:Array = response as Array;
    }
}

That should be it.

Upvotes: 0

Related Questions