2015-11-17 76 views
0

我正在尋找一種方法來根據其post_id檢索喜歡的Facebook帖子的數量。我的PHP代碼保持從這個論壇itself..and它像正在檢索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

添加彙總標誌**摘要=真**

https://graph.facebook.com/ {} POST_ID /喜歡?=的access_token {}令牌總結& =真」

{ 
 
    "data": [ 
 
    { 
 
     "id": "663342380429664", 
 
     "name": "Luis Mendoza" 
 
    }, 
 
    { 
 
     "id": "0840406448", 
 
     "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 
 
    } 
 
}

+0

如果只有總數感興趣,那麼可以/應該增加'limit = 0'。 (這將使'數據'部分只是一個空的數組 - 不需要爲前25個喜歡發送數據,如果它根本沒有興趣。) – CBroe

+0

任何這樣的方式來做同樣的股份? –