Facebook Graph API - 获取页面/群组照片的点赞数
我一直在测试图形 API 并遇到问题。如何从页面/组的照片中获取点赞数?
我是群组的管理员/创建者。在 https://developers.facebook.com/tools/explorer/ 中输入特定照片 ID 时它带来了该组的几乎所有数据,甚至评论,但不包括点赞数。对于类似的部分,它需要(根据文档)访问令牌,尽管任何人都可以访问该信息。
如何获取具有所需权限的页面/组的访问令牌以及如何使用它来获取我需要的信息?
如果可能的话,我想从单个地址获取 JSON。
I've been testing graph API and ran into a problem. How can I get like count from photos of a page/group?
I'm administrator/creator of a group. When entering in https://developers.facebook.com/tools/explorer/ certain photo ID from that group it brings almost all data, even comments, but not the like count. For like part it needs (according to docs) access token despite the fact that anyone can access that info.
How to get access token of my page/group with required permissions and how to use it to get info I need?
If possible I would like to get JSON from a single address if it is possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这可以通过页面实现(即使没有访问令牌!),具体方法如下:
访问图表上的页面
通过转到页面的 url 获取页面的 ID:
https://www.facebook.com/pages/platform/19292868552
网址末尾的数字是页面的 ID。获取该 ID 并将其与图形浏览器一起使用(此处)或直接访问它直接。
访问页面的相册
现在,将相册附加到该网址将为您提供该页面拥有的所有相册,包括墙上的照片:
https://graph.facebook.com/19292868552/albums
输出如下所示:
选择相册
对于data 数组有一个id 和一个name。使用这两个字段,您可以选择包含所需照片的相册。该结果中的第一张专辑是“Bringing Operations Developer Love to Europe”。我们来看看这张专辑的照片。
查看照片
如果您到目前为止已经按照答案进行操作,那么下一步应该相当明显。使用您想要的相册的 id 并将照片附加到图表网址:
https://graph.facebook.com/10150160810478553/photos
查看照片的喜欢
就像选择相册一样,只需使用id 在上述步骤的输出中,并将 likes 附加到网址以查看喜欢的照片:
https:// /graph.facebook.com/10150160813853553/likes
输出:
使用此输出,您可以简单地计算数据数组中的条目数以获得点赞数。
请注意,所有这一切都可以通过使用图形浏览器通过单击输出框中的 id 和连接侧边栏( 除了最后一个 /likes 连接,希望很快就会添加。此外,您不需要访问令牌即可执行任何操作,因为页面是公开的。
This is possible with a page (even without an access token!) and here's how:
Visit the page on the graph
Get the page's id by going to the page's url:
https://www.facebook.com/pages/platform/19292868552
The number on the end of the URL is the page's id. Take that id and use it with the graph explorer (here) or just visit it directly.
Visit the page's albums
Now appending albums to that url will give you all the albums the page has, including wall photos:
https://graph.facebook.com/19292868552/albums
The output looks like this:
Selecting an album
For each object in the data array there is an id and a name. Using these two fields you can select the album that contains the photos you want. The first album in this result is "Bringing Operation Developer Love to Europe". Lets look at this albums photos.
Seeing Photos
If you've followed the answer up to this point the next step should be fairly obvious. Use the id for the album you want and append photos to the graph url:
https://graph.facebook.com/10150160810478553/photos
Seeing a Photo's likes
Much like selecting an album, simply use an id in the output of the above step and append likes to the url to see a photos likes:
https://graph.facebook.com/10150160813853553/likes
Output:
Using this output you can simply count the number of entries in the data array to get the like count.
Note that all of this is possible from using the graph explorer by clicking on ids in the output box and the connections sidebar (except for the last /likes connection, which will hopefully be added soon. I hope this helps. Also, you do not need an access token to do any of this because pages are public. Hope this helps!
您可以通过结合使用 fields 参数和
likes.limit(1).summary(true)
来获取评论/喜欢计数,而无需对所有喜欢进行分页。例如,下面对披萨的搜索 api 查询将为您提供所有公共帖子及其汇总的点赞数:结果(截断):
You can get the comments/likes count without having to paginate through all likes by using the fields parameter in combination with
likes.limit(1).summary(true)
. For example, a search api query for pizza below will give you all public posts and their likes count summarized:results (truncated):
/me/feed 返回一个 LIKES 字段
我使用了一个解决方案,我只需查找数组中显示 LIKES 的项目数
。这将返回对象的“长度”——等于喜欢的数量。
/me/feed returns a LIKES field
I used a solution where I simply find the number of items in the array which display LIKES
This returns the "length" of an object -- which is equal to the number of likes.
http://graph.facebook.com/223766074374957
响应中有一个 Likes 属性
http://graph.facebook.com/223766074374957
there is a likes property in the response