在php中检索Facebook帖子的内容

时间:2015-11-17 12:47:39

标签: php facebook

我正在寻找一种基于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个喜欢的不同页面等等。

有没有办法通过一个查询获得facebook帖子的总数?

1 个答案:

答案 0 :(得分:1)

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

&#34; https://graph.facebook.com/ {POST_ID} /喜欢的access_token = {令牌}&安培;总结=真&#34;

&#13;
&#13;
{
  "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
  }
}
&#13;
&#13;
&#13;