我正在使用PHP SDK处理Facebook API。
我试图浏览用户的帖子,然后循环浏览该帖子上的评论。
我很好地循环播放帖子。但是当我循环浏览评论时,我需要一个对象ID。我已经了解到这与帖子ID不同。我很困惑,因为在我的帖子对象中我只有一个帖子ID,没有对象。我如何/在哪里获得此对象ID?
$request = new FacebookRequest($session, 'GET', '/me/posts');
$response = $request->execute();
$graphObject = $response->getGraphObject()->asArray();
foreach ($graphObject['data'] as $post) {
echo $post->message;
$postId = $post->id;
$commentsRequest = new FacebookRequest($session, 'GET', "/$postId/comments");
$commentsResponse = $commentsRequest->execute();
$commentsGraphObject = $commentsResponse->getGraphObject()->asArray();
// $commentsGraphObject is an empty array here because I am passing the post id and not the object id, which I don't know where to get.
foreach ($commentsGraphObject['data'] as $comment) {
echo $comment->message;
}
}
答案 0 :(得分:0)
您可以使用可用的“ object_id”字段 例如:/ posts /?fields = object_id
您可以在中找到更多信息 https://developers.facebook.com/docs/graph-api/reference/v3.2/post