我正在使用一个Facebook小部件,在其中我想显示所有在其中标记我的页面的公开帖子。目前,我已经成功检索了这些帖子,但是我从Facebook收到的唯一字段是id
,message
和tagged_time
。是否有可能从帖子创建者那里检索一些用户数据,例如姓名和个人资料图片?
这是我当前正在使用的代码:
$pageID = '{page-id}';
$fb = new \Facebook\Facebook([
'app_id' => '{app-id}',
'app_secret' => '{app-secret}',
'default_graph_version' => 'v3.0',
'default_access_token' => '{user-access-token}'
]);
// Get the page access token
$response = $fb->sendRequest('GET', '/' . $pageID, ['fields' => 'access_token'])->getDecodedBody();
try {
$response = $fb->get('/' . $pageID . '/tagged', $response['access_token']);
} catch(\Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
exit;
} catch(\Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
exit;
}
var_dump(json_decode($response->getBody()));
然后响应如下:
object(stdClass)[10442]
public 'data' =>
array (size=1)
0 => object(stdClass)[10440]
public 'message' => string 'This is a message' (length=15)
public 'id' => string '120501758872711_120497812206439' (length=31)
public 'tagged_time' => string '2018-07-19T12:32:51+0000' (length=24)
public 'paging' =>
object(stdClass)[10437]
public 'cursors' =>
object(stdClass)[10439]
public 'before' => string 'Cg8Ic3RvcnlfaWQPEzEyMDQ5NzgxMjIwNjQzOTo1OjAPB3Bvc3RfaWQIAABtl5VK82cPCG93bmVyX2lkCAAAbZAiAiEyHDwR0aW1lBltQhPMB' (length=109)
public 'after' => string 'Cg8Ic3RvcnlfaWQPEzEyMDQ5NzgxMjIwNjQzOTo1OjAPB3Bvc3RfaWQIAABtl5VK82cPCG93bmVyX2lkCAAAbZAiAiEyHDwR0aW1lBltQhPMB' (length=109)