How to parse a facebook graph api response

前端 未结 3 1916
醉酒成梦
醉酒成梦 2021-01-15 09:47

I have a facebook graph api request which brings back this response

Facebook\\GraphObject Object
(
    [backingData:protected] => Array
        (
                 


        
相关标签:
3条回答
  • 2021-01-15 09:51

    Here is the way:

            $user_profile = (new FacebookRequest(
            $session, 'GET', '/me/albums'
            ))->execute()->getGraphObject();
            $album =  $user_profile->getProperty('data');
    
            $album_data = $album->asArray();//this will do all job for you..
            foreach($album_data as $row){
                var_dump($row);
            }
    
    0 讨论(0)
  • 2021-01-15 09:56

    For the New version Graph API v2.5 of Facebook Read read data as below :

    $fb = new \Facebook\Facebook([
            'app_id' => 'KEY HERE',
            'app_secret' => 'SECRET HERE',
            'default_graph_version' => 'v2.5',
        ]);
     $asscee_t ="ACCESS TOKEN HERE";
        $response = $fb->get('/me/friends', $asscee_t);
            $get_data = $response->getDecodedBody(); // for Array resonse
            //$get_data = $response->getDecodedBody(); // For Json format result only
            echo $get_data['summary']['total_count']; die; // Get total number of Friends
    
    0 讨论(0)
  • 2021-01-15 10:06

    https://developers.facebook.com/docs/php/GraphObject/4.0.0

    getProperty

    getProperty(string $name, string $type = 'Facebook\GraphObject') Gets the value of a named key for this graph object. If the value is a scalar (string, number, etc.) it will be returned. If it's an associative array, it will be returned as a GraphObject cast to the appropriate subclass type if provided.

     $user_profile = (new FacebookRequest(
            $session, 'GET', '/me/albums'
        ))->execute()->getGraphObject();
    
    $id = $user_profile->getProperty('id');
    

    full list of field in https://developers.facebook.com/docs/graph-api/reference/v2.0/album

    0 讨论(0)
提交回复
热议问题