Skip navigation
helpAnoobOut
Currently Being Moderated

help me connect to facbook?

Aug 8, 2011 7:54 AM

Can anyone help me, i want to display the news feeds from a facebook page, that is also mobile safe, i want to develop a mobile application..

 

How would this be done, could you show me some example code? or point me to t tutorial or something???

 

All the help will be greatly appreciated.

 
Replies 1 2 Previous Next
  • Currently Being Moderated
    Aug 8, 2011 8:15 AM   in reply to helpAnoobOut

    First thing is to note that Facebook is nightmare to develop with. Then you need to register your app to obtain the ID, to obtain the Access Token

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2011 8:23 AM   in reply to kennethkawamoto2

    Why a nightmare?

    Legal complexity I guess.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2011 8:43 AM   in reply to sexcBoy

    > Why a nightmare?

     

    Poor documentation, unfriendly data format... they also have this habit of changing things without telling anyone

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2011 9:02 AM   in reply to kennethkawamoto2

    The habit of changing everything is due to some guys creating scripts then posting it on http://userscripts.org

    It was cool to see the script which lets you view photos of people who are not your friends.

    If I had time i would work on these clever javascripts.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2011 10:03 AM   in reply to helpAnoobOut

    > ok so once i have the ID then what?

     

    Request a token. Once you have it then call an API using URLLoader

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 8, 2011 10:26 AM   in reply to helpAnoobOut

    This is how you'd start

    var loader:URLLoader = new URLLoader(new URLRequest("https://graph.facebook.com/PAGE ID/feed?access_token=ACCESS TOKEN"));
                loader.addEventListener(Event.COMPLETE, loadComplete);
    }
            
    function loadComplete(e:Event):void {
                trace(e.target.data);
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 1:51 AM   in reply to helpAnoobOut

    So all i have to do is display that code, decode it intto json and then put it into a text field? which  thanks to the help of other people i understand now, but in that code where do i put my acess token????

     

    Facebook returns the data in JSON so you will need to decode it using JSON class by Mike Chambers, just like the way I showed to you for Twitter.

     

    Unlike Twitter, Facebook JSON data is Object so cast the decoded data to Object.

     

    The other difference is that Facebook data is little more complex than Twitter data - there are Likes, comments, Likes to a comment, comments to a comment, etc - so the parsing is little more involved.

     

    Access Token is needed when you call the API. I already showed it to you in my previous post

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 4:08 AM   in reply to kennethkawamoto2

    kennethkawamoto2: Can you show me how to do this? I have really been trying so hard to find out how to do this, i have actually truly tried on my own before seeking help. All the tutorials on the internet show how to do login systems ect. I just want to display the news feeds from a fan page.. PLEASE HELP ME

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 4:16 AM   in reply to gotoAndHelp ( please )

    Sure. I did tell you to get the ID and Token - have you got them? If you do not have them you can't get the feed.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 4:21 AM   in reply to kennethkawamoto2

    yes i have a ID and token. Now what?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 4:34 AM   in reply to gotoAndHelp ( please )

    Can you trace the JSON feed using the code above?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 4:43 AM   in reply to kennethkawamoto2

    i dont know, because i dont understand much about the code above ? i mean i get the url loader bit, then where do i put my id ect?

     

    how do i call the feed from the API, if i know that then i can display it into a text field my self.

     

    Can you show me how to decode it into JSON?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 6:01 AM   in reply to gotoAndHelp ( please )

    There isn't much to it... Say the Page your accessing has the ID 12345678910, and the Access Token you obtained is 123456789123456|aBcDefgHiJKl_12a3C4DE5F6GH, your call to the API would be:

    https://graph.facebook.com/12345678910/feed?access_token=123456789123456|aBcDefgHiJKl_12a3C4DE5F6GH
    
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 6:17 AM   in reply to kennethkawamoto2

    oooh so that would display the feeds of the page? ID is that meaning my id or the page ID?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 7:02 AM   in reply to gotoAndHelp ( please )

    It's the Page ID, not your ID. Try it in the browser first - no need for Flash to test the URL.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 7:05 AM   in reply to kennethkawamoto2

    haha i figured it out literally 10 secs before i read this, but now its displaying this:

     

             "message": "Kissstory on the way to Eaton Sports Therapy sesh, yeeeeea. Brno MotoGP from Friday, nice little break :)",
             "type": "status",
             "application": {
                "name": "Facebook for iPhone",
                "id": "6628568379"
             },

     

     

    well there is alot more than that but thats jsut a segmant. So how can i display just the news feeds from that?

     

    so just what the API determines as "meassage:"

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 7:15 AM   in reply to gotoAndHelp ( please )

    That cannot be the whole data, it's just a segment as you said. Did you try it in the browser?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 7:17 AM   in reply to kennethkawamoto2

    no its not the whole data displayed, if yo want me to show you it all i can? but its basically the same as that. But i want to format it i guess so it only shows the message.. Instead of all that data... Do you know how to do this, i just want to display the "message:" instead of all the data, like twitter you only want to display the tweets..

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 7:40 AM   in reply to gotoAndHelp ( please )

    Ah sorry I misread your post - I thought that's all you received! So you received the JSON data, that's good

     

    Then just decode it to an AS object. Facebook data object has "data" key, whcih holds an Array of wall posts. Once you get to that Array just iterate it to extract the messages.

    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import com.adobe.serialization.json.JSON;
     
    var loader:URLLoader = new URLLoader(new URLRequest("https://graph.facebook.com/XXX/feed?access_token=XXX"));
    loader.addEventListener(Event.COMPLETE, loadComplete);
     
    function loadComplete(e:Event):void {
        processData(e.target.data);
    }
     
    function processData(data:String):void {
        var facebookFeed:Array = JSON.decode(data).data as Array;
        for(var i:uint, feedCount:uint = facebookFeed.length; i < feedCount; i++){
            trace(facebookFeed[i].message);
        }
    }
    

    You should get a bunch of messages in trace.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 7:55 AM   in reply to helpAnoobOut

    THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!, THANK YOU!,

     

     

    Dude you really helped me out man! I Appreciate it more than you can imagine! Thanks!!!

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 8:03 AM   in reply to helpAnoobOut

    Hold on you two are not the same person of course - you guys confused me

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 12, 2011 8:43 AM   in reply to helpAnoobOut

    Nah i saw his twitter api post and thought it would be easy to do the same for facebook.

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2011 1:57 AM   in reply to helpAnoobOut

    There are so many different ways to display this data and it's all down to how you want to display. I show you the most rudimentary way here with a TextField:

    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import com.adobe.serialization.json.JSON;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
     
    var textfield:TextField = new TextField();
    with(textfield){
        x = 10;
        y = 10;
        width = 400;
        autoSize = TextFieldAutoSize.LEFT;
        wordWrap = true;
        multiline = true;
    }
    addChild(textfield);
     
    var messages:String = new String();
     
    var facebookAPI:String = "https://graph.facebook.com/XXX/feed?access_token=XXX";
    var loader:URLLoader = new URLLoader(new URLRequest(facebookAPI));
    loader.addEventListener(Event.COMPLETE, loadComplete);
     
    function loadComplete(e:Event):void {
        processData(e.target.data);
    }
     
    function processData(data:String):void {
        var facebookFeed:Array = JSON.decode(data).data as Array;
        for (var i:uint, feedCount:uint = facebookFeed.length; i < feedCount; i++) {
            // trace(facebookFeed[i].message);
            messages += facebookFeed[i].message + "\n\n";
        }
        textfield.text = messages;
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2011 4:00 AM   in reply to helpAnoobOut

    What kind of positions?

     
    |
    Mark as:
  • Currently Being Moderated
    Aug 15, 2011 5:01 AM   in reply to helpAnoobOut
    import flash.net.URLLoader;
    import flash.net.URLRequest;
    import flash.events.Event;
    import com.adobe.serialization.json.JSON;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.geom.Point;
     
    var positions:Vector.<Point> = new Vector.<Point>();
    positions.push(new Point(20, 90));
    positions.push(new Point(20, 140));
    positions.push(new Point(20, 190));
    positions.push(new Point(20, 240));
    positions.push(new Point(20, 290));
    positions.push(new Point(20, 340));
    positions.push(new Point(20, 390));
     
    var facebookAPI:String = "https://graph.facebook.com/XXX/feed?access_token=XXX";
    var loader:URLLoader = new URLLoader(new URLRequest(facebookAPI));
    loader.addEventListener(Event.COMPLETE, loadComplete);
     
    function loadComplete(e:Event):void {
        processData(e.target.data);
    }
     
    function processData(data:String):void {
        var facebookFeed:Array = JSON.decode(data).data as Array;
        for (var i:uint, feedCount:uint = 7; i < feedCount; i++) {
            var textfield:TextField = new TextField();
            with(textfield){
                x = positions[i].x;
                y = positions[i].y;
                width = 400;
                autoSize = TextFieldAutoSize.LEFT;
                wordWrap = true;
                multiline = true; 
                text = facebookFeed[i].message;
            }
            addChild(textfield);
        }
    }
    
     
    |
    Mark as:
  • Currently Being Moderated
    Dec 21, 2011 7:32 PM   in reply to kennethkawamoto2

    Hi, this is really clear and concise. It is so easy to understand.

    I wonder if you have a similar piece of code - as easy as this, that shows me how to post a pre-formatted message to my page?

    I want to be able to post my geiolocation to my facebook page from the press of a button.

     

    Of course there is a lot more code related to this, but consider this pseudo code for this question.

    [Send to Facebook]

     

    sendToFacebook(); {

    location = "http://maps.google.com/maps?q=38.714008,+-122.41675&iwloc=A&hl=en&ll=3 7.714008,-122.4167&output=embed&z=13";

    /* authorize */

    /* send the location string to facebook page */

    /* return */

     

    }

     

    This is probably too much to ask, sorry, but your code is really clear, so I just thought I'd ask.

     

    Thanks

    Robert

     
    |
    Mark as:
  • Currently Being Moderated
    Dec 22, 2011 3:00 AM   in reply to rachalmers
     
    |
    Mark as:
1 2 Previous Next

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points