让Facebook喜欢/分享给定URL的数量

Vij*_*ati 56 facebook facebook-fql facebook-graph-api

我正在使用Facebook API获取给定URL的类似/共享计数.奇怪的是,返回结果似乎很不一致.例如,此页面返回结果:

https://api.facebook.com/method/fql.query?query=select%20total_count,like_count,comment_count,share_count,click_count%20from%20link_stat%20where%20url='http://www.groupon.com/deals/seattlehelitourscom-by-classic-helicopter-corp'&format=json

然而,这个不是:

https://api.facebook.com/method/fql.query?query=select%20total_count,like_count,comment_count,share_count,click_count%20from%20link_stat%20where%20url='http://www.livingsocial.com/deals/278194-sunset-kayaking-hot-chowder'&format=json

第二页显然有一个共享计数,当我检查页面的HTML时,用于共享的URL是我在上面的API请求中放置的URL.但是,API不响应任何数量的喜欢或分享的任何计数信息.

关于为什么API可能会响应某些URL而不是其他URL的任何线索?

Raj*_*ase 47

更新: 此解决方案不再有效.FQL自2016年8月7日起不再使用.


https://api.facebook.com/method/fql.query?query=select%20%20like_count%20from%20link_stat%20where%20url=%22http://www.techlila.com%22

另外http://api.facebook.com/restserver.php?method=links.getStats&urls=http://www.techlila.com将显示所有数据,如"分享计数","赞计数"和"评论计数" '以及所有这些的总和.

根据您的需要更改URL(即http://www.techlila.com).

这是正确的URL,我得到了正确的结果.

编辑(2017年5月):从v2.9开始,您可以进行图形API调用,其中ID是URL并选择"参与"字段,下面是图表资源管理器中示例的链接.

https://developers.facebook.com/tools/explorer/?method=GET&path=%3Fid%3Dhttp%3A%2F%2Fcomunidade.edp.pt%26fields%3Dengagement&version=v2.9

  • 可以以JSON格式获得相同的结果:https://graph.facebook.com/fql?q = select%20%20like_count%20from%20link_stat%20where%20url =%22http://yoast.com%22 (10认同)
  • 从API 2.1+开始,FQL确实已被弃用.查看下面的vincentlcy的答案或http://stackoverflow.com/questions/4764562/is-it-possible-to-get-the-number-of-facebook-likes-for-a-url/5899343#5899343 (3认同)
  • 是的,它是官方API的一部分.此请求使用Facebook查询语言(FQL)http://developers.facebook.com/docs/technical-guides/fql/ (2认同)

bud*_*udi 42

截至2016年8月8日,FQL已被弃用.


更新10/2017(v2.10):

这是一种非弃用的方式来获取给定的URL和共享计数(不需要访问令牌):

https://graph.facebook.com/?fields=og_object{likes.summary(total_count).limit(0)},share&id=https://www.stackoverflow.com


结果:

{
   "og_object": {
      "likes": {
         "data": [

         ],
         "summary": {
            "total_count": 83
         }
      },
      "id": "10151023731873397"
   },
   "share": {
      "comment_count": 0,
      "share_count": 2915
   },
   "id": "https://www.stackoverflow.com"
}
Run Code Online (Sandbox Code Playgroud)

JQuery示例:

$.get('https://graph.facebook.com/'
    + '?fields=og_object{likes.summary(total_count).limit(0)},share&id='
    + url-goes-here,
    function (data) {
        if (data) {
            var like_count = data.og_object.likes.summary.total_count;
            var share_count = data.share.share_count;
        }
    });
Run Code Online (Sandbox Code Playgroud)

参考:

https://developers.facebook.com/docs/graph-api/reference/url


Joh*_*ner 17

使用开放图API.这是一个现实的例子,询问有多少人喜欢"可口可乐".

https://developers.facebook.com/tools/explorer/?method=GET&path=cocacola%3Ffields%3Dlikes

归结为:

https://graph.facebook.com/cocacola?fields=likes

您可以在AJAX GET中执行哪些操作

结果是:

{
  "likes": 71717854, 
  "id": "40796308305"
}
Run Code Online (Sandbox Code Playgroud)

  • 需要访问令牌来请求此资源. (2认同)

jet*_*lej 11

之前的所有答案都已被弃用.此方法适用于2016年8月:


要获得任何URL的计数:

GET请求:https://graph.facebook.com/ [url] / access_token = [access_token]

然后从返回的JSON对象中获取shares-> share_count.


Facebook页面的粉丝数:

GET请求:https://graph.facebook.com/ [url]/?fields = fan_count&access_token = [access_token]

然后从返回的JSON对象中获取"fan_count"字段.


您可以使用Graph API Explorer测试并获取访问令牌

  • 对于URL,shares_count返回份额数+喜欢的数量. (3认同)

Cha*_*hak 7

Facebook Graph非常棒.只需做下面的事情.我已经输入了perl.org URL,你可以在那里放任何URL.

https://graph.facebook.com/fql?q=SELECT%20like_count,%20total_count,%20share_count,%20click_count,%20comment_count%20FROM%20link_stat%20WHERE%20url%20=%20%27http://perl.org %27

  • 这不再起作用了(`(#12)vql不支持v2.1及更高版本`) (2认同)

vin*_*lcy 7

对于最新的2.1 Graph API,将获得imdb.com的喜欢的示例

用它来获取id https://developers.facebook.com/tools/explorer/?method=GET&path=%3Fid%3Dhttp%253A%252F%252Fwww.imdb.com%3Ffields%3Dlikes&version=v2.1

然后得到喜欢

https://developers.facebook.com/tools/explorer/?method=GET&path=414652589771%2Flikes&version=v2.1

文献

URL /?id={url}

Represents an external URL as it relates to the Facebook social graph - shares and comments from the URL on Facebook, and any Open Graph objects associated with the URL.
Run Code Online (Sandbox Code Playgroud)

参考 http://harshtechtalk.com/how-get-likes-count-posts-comments-facebook-graph-api/