【问题标题】:Retrieving likes of Facebook Posts in php在 php 中检索 Facebook 帖子的喜欢
【发布时间】:2015-11-18 20:13:00
【问题描述】:

我正在寻找一种方法来根据其 post_id 检索 Facebook 帖子的点赞数。我从这个论坛本身获得了一个 php 代码。它有点像

 <?php
    function fetchUrl($url){
       return file_get_contents($url);
   }        

    $json_object = fetchUrl("https://graph.facebook.com/{post_id}/likes?access_token={token}&limit=5000000"); // 
    $feedarray   = json_decode($json_object, true);
    $likesNum = count($feedarray['data']); // return the number of items in `data` array

    print $likesNum;
?>

但问题是此方法无法检索帖子的总点赞数,因为点赞数以 1000 个为单位显示,然后会有另一个链接指向包含下一组 1000 个点赞数的不同页面,依此类推。

p>

有没有一种方法可以通过单个查询获得 Facebook 帖子的总点赞数?

【问题讨论】:

    标签: php facebook


    【解决方案1】:

    添加摘要标志** summary=true**

    https://graph.facebook.com/{post_id}/likes?access_token={token}&summary=true”

    {
      "data": [
        {
          "id": "663342380429664",
          "name": "Luis Mendoza"
        },
        {
          "id": "1532100840406448",
          "name": "Sakazuki Akainu"
        },
        {
          "id": "780666205412913",
          "name": "Joaito KoRn"
        },
        {
          "id": "1060933433919925",
          "name": "Adrian Sosa"
        },
        {
          "id": "860704407276452",
          "name": "Sarah Rosenstrauch"
        },
        {
          "id": "1947974762009431",
          "name": "David Prieto"
        },
        {
          "id": "804864302928112",
          "name": "Ronal Ortega"
        },
        {
          "id": "1505075359814934",
          "name": "Gonzalo Larzen"
        },
        {
          "id": "1431207613804483",
          "name": "Victor Clc"
        },
        {
          "id": "508785009283633",
          "name": "Rxdry EzDe Cerrx Mcmxii"
        },
        {
          "id": "435355413265946",
          "name": "Ángel Fernando Huillca Alonso"
        },
        {
          "id": "163773913961445",
          "name": "Pelado Miguel Pin Macias"
        },
        {
          "id": "1479227465674392",
          "name": "Releck Solitario"
        },
        {
          "id": "161610054193539",
          "name": "MD Sahin MD Sahin"
        },
        {
          "id": "798431050242097",
          "name": "Brian Nahuel"
        },
        {
          "id": "624869574305480",
          "name": "Saul Alfredo"
        },
        {
          "id": "1642733362665392",
          "name": "Junior Zurita"
        },
        {
          "id": "134907406871404",
          "name": "Wil Peña"
        },
        {
          "id": "10153052770952668",
          "name": "Miguel Peña Cáceres"
        },
        {
          "id": "1461494580846182",
          "name": "Darian Suarez"
        },
        {
          "id": "365762500250317",
          "name": "Igarashi Ganta"
        },
        {
          "id": "750032685093387",
          "name": "Camila Barbé"
        },
        {
          "id": "781013541941152",
          "name": "Gonzalo Nievas"
        },
        {
          "id": "756520927743339",
          "name": "Jonathan C. Duran Cuellar"
        },
        {
          "id": "1504488093199860",
          "name": "Maxi Russo"
        }
      ],
      "paging": {
        "cursors": {
          "before": "NjYzMzQyMzgwNDI5NjY0",
          "after": "MTUwNDQ4ODA5MzE5OTg2MAZDZD"
        },
        "next": "https://graph.facebook.com/v2.3/1009501939072385/likes?access_token=TOKEN..."
      },
      "summary": {
        "total_count": 4303
      }
    }

    【讨论】:

    • 如果只关注总数,则可以/应该添加limit=0。 (这将使data 部分只是一个空数组 - 如果根本不感兴趣,则无需发送前 25 个喜欢的数据。)
    • 有什么方法可以对共享做同样的事情吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多