我有一个facebook图形api请求,它返回以下响应
Facebook\GraphObject Object
(
[backingData:protected] => Array
(
[data] => Array
(
[0] => stdClass Object
(
[id] => 111
[from] => stdClass Object
(
[id] => 111
[name] => fo bar
)
[name] => etc
)
我试过做$reponse->{'backingData:protected'}
,但它不起作用。
另外,下一组结果是指向图形api的链接,但其中的结果是纯json。
[paging] => stdClass Object
(
[cursors] => stdClass Object
(
[after] => MTI3NzMzMTQwMzYy
[before] => MTAxNTQzNjI5NTY1NDAzNjM=
)
[next] => https://graph.facebook.com/v2.0/111/albums?access_token=xxxxv&limit=25&after=yyy
)
我的代码
$user_profile = (new FacebookRequest(
$session, 'GET', '/me/albums'
))->execute()->getGraphObject();
echo '<pre>'; print_r($user_profile); echo '</pre>';
发布于 2014-07-23 05:49:25
下面是方法:
$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);
}
发布于 2016-03-04 15:23:03
对于Facebook的新版本Graph API v2.5读取数据,如下所示:
$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
发布于 2014-07-23 05:41:35
https://developers.facebook.com/docs/php/GraphObject/4.0.0
getProperty
getProperty(string $name, string $type = 'Facebook\GraphObject')
获取此图形对象的命名键的值。如果值是标量(字符串、数字等)它将会被退还。如果它是一个关联数组,它将作为GraphObject类型返回给适当的子类类型(如果提供)。
$user_profile = (new FacebookRequest(
$session, 'GET', '/me/albums'
))->execute()->getGraphObject();
$id = $user_profile->getProperty('id');
https://developers.facebook.com/docs/graph-api/reference/v2.0/album中字段的完整列表
https://stackoverflow.com/questions/24897838
复制相似问题