Facebook like count url

后端 未结 2 933
滥情空心
滥情空心 2021-01-17 05:21

As Facebook changed their API and deprecated the old one, I need to get data (likes count, share count, comment count) about single pages.

I figured out how to get

相关标签:
2条回答
  • 2021-01-17 05:48

    The API Explorer adds the Access Token automatically, but you have to add it manually in your URL:

    https://graph.facebook.com/?fields=og_object{likes.limit(0).summary(true)},share&ids=http://www.businessinsider.com/airlines-dont-disclose-carrier-fee-that-inflates-ticket-prices-2016-9&access_token=xxx
    

    Result:

    {
      "http://www.businessinsider.com/airlines-dont-disclose-carrier-fee-that-inflates-ticket-prices-2016-9": {
        "og_object": {
          "likes": {
            "data": [
            ],
            "summary": {
              "total_count": 0,
              "can_like": true,
              "has_liked": false
            }
          },
          "id": "949055545223224"
        },
        "share": {
          "comment_count": 0,
          "share_count": 346
        },
        "id": "http://www.businessinsider.com/airlines-dont-disclose-carrier-fee-that-inflates-ticket-prices-2016-9"
      }
    }
    
    0 讨论(0)
  • 2021-01-17 06:10

    The results of json_decode() are Objects. So you can easily browse through like this:

    <?php    
    
    $url = 'https://graph.facebook.com/?fields=og_object{likes.limit(0).summary(true)},share&ids=http://www.businessinsider.com/airlines-dont-disclose-carrier-fee-that-inflates-ticket-prices-2016-9';
    
    $json = file_get_contents($url);
    $json_output = json_decode($json);
    foreach( $json_output as $site=>$data ){
        echo $site."\n";
        echo $data->og_object->likes->summary->total_count;
    }
    
    ?>
    
    0 讨论(0)
提交回复
热议问题