Facebook API - Help with introduction

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Facebook API - Help with introduction

    Hello guys,

    Anyone can help with an introduction on how to use Facebook API?
    An example on how to get status, or get someone's wall, would be cool!
    mysterio.al - programming is a functional art

    #2
    Download the php sdk. Register ur app, configure it wit ur keys. Request perms (publish_stream) then instantiate a fb object
    PHP Code:
    $facebook = new Facebook(array('api_key'=>'sh.it','secret'=>'fu.ck','cookies'=>true));
    $session=$facebook->getSession();
    $fbme=false;
    try{
    $fbme=$facebook->api('/me');
    }catch(
    FacebookApiException $e){
    die(
    $e);
    }

    if(
    $fbme){
    try{
    $facebook->api('me/feed','post',array('message'=>'MY STATUS MESSAGE','cb'=>''));
    }catch(
    FacebookApiException $e){
    die(
    'Couldnt update status. Facebook said:'.$e);
    }
    }else{
    header('Location: '.$facebook->getLoginUrl('req_perms'=>'publish_stream'));
    exit;

    Added after 2 minutes:

    Getting status requires read_stream permission. After getting the permission, run
    $status=$facebook->api('/me/status');
    i think.
    Last edited by CreativityKills; 30.07.10, 14:03.

    Comment


      #3
      Good, thank you (I will try it)!

      And what if we need to get someone's wall? I am asking for different actions to see how it works!
      mysterio.al - programming is a functional art

      Comment


        #4
        You CANT get sumones wall without having offline_access,read_stream permissions.
        $facebook->api('/username/feed');

        Comment


          #5
          I was looking at official Facebook API page and I started using Graph API.
          This looks faster (I don't know if better).

          To get someone's wall, just type "http: // graph.facebook.com/(user-id)/feed".
          This step is passed, but the problem now is how to style the result, as what is being showed from that URL is:
          {"data":[{"id":"1670158248_133190916717388","from":{"name": "Ervis Mysterio","id":"1670158248"},"message":"Hello All"... (continues till end of wall)

          Can I suggest me any way of styling it?
          mysterio.al - programming is a functional art

          Comment


            #6
            You already ave d result. It was JSON decoded into an array. So just use it as u wud any array.
            PHP Code:
            $fbme=$facebook->api('/me/feed?limit=10&fields=from,id,message'); /// use limit parameter when requesting data thats plenty e.g wall posts.
            foreach($fbme['data'] as $data){
            echo 
            $data['from']['name'].': '.$data['message'].'<br/>';

            Get it? Fbook sends a json encoded reply, the api decodes and changes it to arrays. Just work with that.

            Comment


              #7
              So there is no way to display feed as html on a website different from fb, without having an app, api key and secret key?

              If no, how should this application be, and can a single application be used in different actions (in different websites for example with different purposes for different fb users)?

              p.s. Sorry for lot of questions, you are not obligated to answer everytime!
              mysterio.al - programming is a functional art

              Comment


                #8
                Originally posted by Mysterio3 View Post
                So there is no way to display feed as html on a website different from fb, without having an app, api key and secret key?

                If no, how should this application be, and can a single application be used in different actions (in different websites for example with different purposes for different fb users)?

                p.s. Sorry for lot of questions, you are not obligated to answer everytime!
                You cant use facebook api without api key and secret code.
                You will need to add codes for different actions in different pages of web sites using facebook api.

                Comment


                  #9
                  Yup thats ur answer.

                  Comment

                  Working...
                  X