是否可能获得一个URL的Facebook的数量? [英] Is it possible to get the number of facebook likes for a url?

查看:277
本文介绍了是否可能获得一个URL的Facebook的数量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

理想情况下,我想使用javascript客户端脚本。如果这是不可能的,那么我想这样做,以使服务器做最少的工作量。

Ideally I would like to do this using javascript client side scripting only. If that is not possible then I'd like to do this in such a way as to have the server do the least amount of work.

任何帮助。

推荐答案

=https://graph.facebook.com/?ids=http://www.stackoverflow.com =nofollow> https://graph.facebook.com/?ids=http://www。 stackoverflow.com 将返回该网址的SHARES数,这与喜欢数不同,因为它还包括评论和其他共享形式。这可能是也可能不是重要的区别。

Actually, https://graph.facebook.com/?ids=http://www.stackoverflow.com will return the number of SHARES for that url, which is distinct from the number of likes because it also includes comments and other forms of sharing. This may or may not be an important difference.

使用Graph API 2.1+有两种方法...虽然现在都需要访问令牌。

With Graph API 2.1+ there are two methods...though both now require access tokens. See below on how to get an access token that lasts forever and is not related to a user session.

喜欢URL计数::

Like count for URLs:


  1. 首先,您需要获取网址的ID:
    https://graph.facebook.com/?id=http://www.stackoverflow.com
    (您不需要访问令牌)

  2. 一旦您拥有该ID,就可以通过喜欢的端点获得类似的计数。您可以访问json响应的摘要部分中的总计数。以下是示例请求: https://graph.facebook.com/10150180465825637 / likes /?summary = true& access_token = TOKEN_GOES_HERE
    (您在这里需要有效的访问令牌,但您可以使用应用访问令牌 - 见下文)

  1. First, you need to get the ID of the URL: https://graph.facebook.com/?id=http://www.stackoverflow.com (you do not need an access token for this)
  2. Once you have the id, you can get the like count via the likes endpoint. You can access the total count in the summary part of the json response. Here's an example request: https://graph.facebook.com/10150180465825637/likes/?summary=true&access_token=TOKEN_GOES_HERE (you need a valid access token here, but you can use app access token - see below)

喜欢Facebook专页数


  1. 类似的计数直接通过: https://graph.facebook.com/FacebookDevelopers/ ?fields = likes& access_token = TOKEN_GOES_HERE
    (您在这里需要一个有效的访问令牌,但您可以使用应用访问令牌 - 见下文)

如何获取永久访问令牌(应用访问令牌)

您可以使用用户访问

您需要使用应用程序访问令牌,这将允许您使用应用程序访问令牌来获取这些结果,但通常对于不是选项的类似计数脚本。以在没有活动用户访问令牌会话的情况下运行脚本离线。以前,您不得不请求一个应用程序访问令牌,现在它是简单的连接的应用程序ID和秘密与|如下:

You'll need to use the App Access Token instead, which will allow you to run the script "offline" without an active user access token session. Previously you had to request an app access token, now it is as simple as concatenating the app id and secret with | as follows:

MY_APP_ID|MY_APP_SECRET

换句话说,上面的完整请求类似:

In otherwords, the full request from above would be something like:

https://graph.facebook.com/10150180465825637/likes/?summary=true&access_token=MY_APP_ID|MY_APP_SECRET

Keep请注意,由于此请求需要应用程序密码,因此您应始终在服务器端执行此请求

Keep in mind that since the app secret is required for this request you should always perform this request server-side. Client-side requests would expose your app secret to everyone.

在以前的Graph API版本(2.0及更低版本)中,可以使用FQL:

In previous versions of Graph API (2.0 and lower) you could use FQL:


SELECT like_count FROM link_stat WHERE url =http://www.stackoverflow.com

SELECT like_count FROM link_stat WHERE url="http://www.stackoverflow.com"

这里是实际的链接。在写这篇文章时,大约有200个喜欢和2000+的分享,所以这是一个很大的区别...

Here is the actual link. There about 200 likes and 2000+ shares as of this writing, so it's a big difference...

这篇关于是否可能获得一个URL的Facebook的数量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆