【问题标题】:Request to get total count of Facebook page likes in v2.3 API请求在 v2.3 API 中获取 Facebook 页面喜欢的总数
【发布时间】:2015-04-17 14:35:47
【问题描述】:

以前我为此使用 FQL,但从 v2.1 开始不推荐使用,我正在使用图形边缘“喜欢”转移到 v2.3。

这是我的网址:

https://graph.facebook.com/v2.3/<page_id>/likes?access_token=<access_token>&summary=true

这将返回带有分页信息的详细 JSON - 但它省略了应该在使用“summary=true”时返回的 total_count,如 Facebook docs 中所述 - 你会看到什么我是说。

【问题讨论】:

    标签: facebook facebook-graph-api


    【解决方案1】:

    现在(2016 年 4 月)偶然发现此答案的任何人都会感到沮丧,因为已接受的答案在 v2.6 中不再有效

    ?fields=likes/likes 现在返回相同的结果 -> 页面喜欢的页面。

    要获取粉丝数量,您现在需要使用 fields=fan_count

    https://graph.facebook.com/pepsius/?fields=fan_count&access_token=<access_token>
    

    如上所示,你也可以直接用pagename发出请求,不需要获取pageID。

    【讨论】:

    • 正确,我已将其更新为正确答案。
    • 你是一个救生员。这不在他们的文档中!
    • 我的 &lt;page_id&gt; 是一个网站 URL。这不适用于 URL (#100) Tried accessing nonexisting field (fan_count) on node type (URL)
    • @Marie-LouiseJournocode 抱歉回复晚了。您需要创建一个应用程序,然后调用以获取 access_token。更多信息:developers.facebook.com/docs/facebook-login/access-tokens/…
    • 对不起@StephenBugsKamenar 我认为这仅适用于实际的 Facebook 页面。
    【解决方案2】:

    您要查找喜欢该页面的总人数或该页面喜欢的内容?

    例如。

    https://graph.facebook.com/v2.3/56381779049/likes?access_token=<access_token>&summary=true
    

    将返回页面 PepsiUS 喜欢的内容。

    https://graph.facebook.com/v2.3/56381779049?fields=likes&access_token=<access_token>
    

    将返回喜欢该页面的总人数。

    {"likes": 32804486, 
    "id": "56381779049"}
    

    在此处验证PepsiUS

    【讨论】:

    • 第二个,即?fields=likes。
    • 我相信不同之处在于 PageID/Likes 是一个 Endpoint,它将返回目标页面喜欢的其他页面。 PageID?fields=Likes 是对页面/用户的边缘计数。
    • 谢谢,这很容易
    【解决方案3】:

    感谢@NativePaul

    我花了将近两天的时间来寻找一种解决方案,以将 Facebook 粉丝页面的点赞计数器以数值形式转换为简码。所以我修改了从这个链接得到的代码:http://www.internoetics.com/2015/07/13/display-number-facebook-page-likes-wordpress-php/

    并对其进行了修改以使用 fan_count 字段,这是供您参考的代码:

    /*
    	Display the Number of Facebook Page Likes in Plain Text with WordPress Shortcode (and PHP)
    	Shortcode: [fbpagelikes id="" appid="" appsecret="" cache="" n="1"]
    */
    
    
    function internoetics_fb_pagelikes($atts) {
      extract(shortcode_atts(array(
        'id' => 'kenryscom',
        'appid' => 'xxxxxxxxxxxxxxxx',
        'appsecret' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
        'n' => 1,
        'cache' => 3600 * 24 * 1
      ), $atts));
    
     $fbcounthash = md5("$url.$cache.$appid.$appsecret.$n");
     $fbcountrecord = 'fblikes_' . $fbcounthash;
     $cachedposts = get_transient($fbcountrecord);
     if ($cachedposts !== false) {
     return $cachedposts;
    
      } else {
    
      $json_url ='https://graph.facebook.com/' . $id . '?fields=fan_count&access_token=' . $appid . '|' . $appsecret;
      $json = file_get_contents($json_url);
      $json_output = json_decode($json);
     
      if($json_output->fan_count) {
       $fan_count = $json_output->fan_count;
       if ($n) $fan_count = number_format($fan_count);
       set_transient($fbcountrecord, $fan_count, $cache);
       return $fan_count;
        } else {
       return 'Unavailable';
      }
     }
    }
    add_shortcode('fbpagelikes','internoetics_fb_pagelikes');

    您必须将上述代码添加到主题函数文件中,并在代码开头提到的任何地方使用简码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-15
      相关资源
      最近更新 更多