Reading data from Facebook graphObject

本秂侑毒 提交于 2019-12-05 02:14:20

If you have casted the response as a GraphObject by using one of the following two methods:

// Get the response typed as a GraphLocation
$loc = $response->getGraphObject(GraphLocation::className());

// or convert the base object previously accessed
// $loc = $object->cast(GraphLocation::className());

You can use the Get properties of the graph object, depending on what kind of object you've casted it as... here's an example for the GraphUser Object:

echo $user->getName();

Or, if you know the name of the property (as shown in the base data), you can use getProperty():

echo $object->getProperty('name');

So in your example, you can use the following to get the id property:

echo $user->getProperty('id');

More examples and documentation here

In the New version of Graph API getProperty does not work. For the New version Graph API v2.5 of Facebook Read read data as below :

$fb = new \Facebook\Facebook([
        'app_id' => 'APPIDHERE',
        '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

Note that from API version >= 5.0.0 getProperty() has been renamed to getField(). It will be removed from >= v6. So

Instead of

$user->getProperty('name')

Use

$user->getField('name')
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!