Tiara Larasati
Tiara Larasati

Reputation: 355

Get Total Comment, Like, Share (PHP Facebook API v2.4)

I've read facebook documentation about comment and like but still confused how to get total comment, like and share from my facebook page feed.

Example how i get comment from my page feed :

$facebook = new Facebook\Facebook([
    'app_id' => '',
    'app_secret' => '',
    'default_access_token' => '',
    'default_graph_version' => 'v2.4'
]);

$response = $facebook->get(id/comments?summary=true&fields=from,parent,id,message,created_time&filter=stream')->getGraphEdge();

print_r($response);

Response result :

[metaData:protected] => Array
    (
        [summary] => Array
            (
                [order] => chronological
                [total_count] => 16
                [can_comment] => 
            )

    )
[items:protected] => Array
    (
        [0]
        ...
        [15]
    )

I know how to get field data, i use $response->asArray(); but how to get summary -> total_count ?

Upvotes: 1

Views: 581

Answers (1)

Yassine Guedidi
Yassine Guedidi

Reputation: 1715

There is a helper function $response->getTotalCount().

For any other value, you can use $response->getMetadata()['summary']['order'].

Upvotes: 1

Related Questions