PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, March 2, 2022

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

 March 02, 2022     facebook, facebook-graph-api, facebook-php-sdk, php     No comments   

Issue

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 ?


Solution

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

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



Answered By - Yassine Guedidi
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing