I'm working with the Facebook API using the PHP SDK.
I'm trying to loop through a user's posts and then loop through the comments on that post.
I'm looping through the posts fine. But when I go to loop through the comments, I need an object id. I've learned this is different than the post id. I'm confused though, because in my post object i only have a post id, there is no object it. How/where do I get this object 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;
}
}
You can use "object_id" field available Ex: /posts/?fields=object_id
you can find more info in https://developers.facebook.com/docs/graph-api/reference/v3.2/post