Dor
Dor

Reputation: 13

Get post details by post id using open graph

By using this code:

$url2 = "https://graph.facebook.com/{$group_id}/feed?limit=500&access_token=XXXXXXXXXXXXX";
$data = json_decode(file_get_contents($url2));

I get json like this:

stdClass Object
(
    [message] => bla bla bla bla bla bla
    [updated_time] => 2016-12-23T08:31:25+0000
    [id] => 000000000000_111111111111
)

The first part (0000...0) is the group id. The second part (1111..1) is the post id. I need the details of the post owner (id, name, profile picture).

You can help me please? Thanks.

Upvotes: 1

Views: 387

Answers (1)

andyrandy
andyrandy

Reputation: 74014

The API reference tells you which fields you can get for a post: https://developers.facebook.com/docs/graph-api/reference/v2.8/post

For example, to get the name of the creator:

/{group-id}/feed?limit=500&fields=id,from

...or if you want to get profile pictures too:

/{group-id}/feed?limit=500&fields=id,from{id,name,picture}

It is called "Declarative Fields" and came with v2.4 of the Graph API. You need to specify the fields you want to get in the result.

Upvotes: 1

Related Questions