php Facebook API:获得页面/群组帖子点赞、分享、评论数的最佳方式?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19061937/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Facebook API: best way to get like, share, comment count for a page/group post?
提问by DamnSemicolon
What's the best way to get the like, share, comment count for a post?
获得帖子点赞、分享、评论数的最佳方式是什么?
I'm trying via FQL but it doesn't seem to give any data when the URL is a FB post URL:
我正在尝试通过 FQL,但当 URL 是 FB 帖子 URL 时,它似乎没有提供任何数据:
SELECT like_count, comment_count, share_count FROM link_stat WHERE url="https://www.facebook.com/Macklemore/posts/10153256675935268"
从 link_stat WHERE url="https://www.facebook.com/Macklemore/posts/10153256675935268" 中选择like_count、comment_count、share_count
When I get the post info via the Graph API Explorer:
当我通过 Graph API Explorer 获取帖子信息时:
386050065267_10153256675935268
386050065267_10153256675935268
It gives me the like count and share count and I can get the comment count via 386050065267_10153256675935268/comments?summary=true
它给我点赞数和分享数,我可以通过以下方式获得评论数 386050065267_10153256675935268/comments?summary=true
{
"id": "386050065267_10153256675935268",
"from": {
"category": "Musician/band",
"name": "Macklemore",
"id": "386050065267"
},
"message": "We're playing a FREE show in November to celebrate the new Microsoft Store opening in Hymansonville, Florida. Come see us! Info here: http://msft.it/STJevent\n\nThursday, November 21, 2013\n10:00 p.m.\nStart lining up for your chance to attend the show on Saturday.\nLocation: Outdoors behind Oakley, near Dick's Sporting Goods.",
"actions": [
{
"name": "Comment",
"link": "https://www.facebook.com/386050065267/posts/10153256675935268"
},
{
"name": "Like",
"link": "https://www.facebook.com/386050065267/posts/10153256675935268"
}
],
"privacy": {
"value": ""
},
"type": "status",
"status_type": "mobile_status_update",
"created_time": "2013-09-26T16:30:23+0000",
"updated_time": "2013-09-27T20:39:45+0000",
**"shares": {
"count": 274
},**
"likes": {
"data": [
{
"name": "Jabson Ramos",
"id": "100005418486411"
},
{
"name": "Sophia Belen Parada Andrades",
"id": "100002552653152"
},
{
"name": "Oli Barrera",
"id": "100001718791443"
},
{
"name": "Viktoria Martinez",
"id": "1697663024"
}
],
**"count": 3345**
},
"comments": {
"data": [
{
"id": "10153256675935268_43537841",
"from": {
"name": "Vu Thai",
"id": "1338690172"
},
"message": "Sean Viray Matt Win Soo... about my birthday weekend...",
"message_tags": [
{
"id": "75311036",
"name": "Sean Viray",
"type": "user",
"offset": 0,
"length": 10
},
{
"id": "25113189",
"name": "Matt Win",
"type": "user",
"offset": 11,
"length": 8
}
],
"can_remove": false,
"created_time": "2013-09-26T16:31:03+0000",
"like_count": 4,
"user_likes": false
},
.....
],
"paging": {
"cursors": {
"after": "MjY=",
"before": "MQ=="
},
"next": "https://graph.facebook.com/386050065267_10153256675935268/comments?limit=25&after=MjY="
}
}
}
Weird thing is when I run that query in my app I don't get the share count or like count. Am I doing something wrong? Is the data in the explorer different from what apps have access to?
奇怪的是,当我在我的应用程序中运行该查询时,我没有得到共享计数或喜欢计数。难道我做错了什么?资源管理器中的数据与应用程序有权访问的数据不同吗?
I know I can get the like count via 386050065267_10153256675935268/likes?summary=true
我知道我可以通过 386050065267_10153256675935268/likes?summary=true 获得点赞数
Biggest thing would be the missing share count.
最大的问题是缺少份额数。
So summary,
所以总结,
Can you get these stats via FQL? If not, how can you obtain the share count via the graph API?
你能通过 FQL 获得这些统计数据吗?如果没有,您如何通过图形 API 获取共享计数?
回答by Stéphane Bruckert
POST_ID?fields=likes.summary(true),comments.summary(true),shares
Result:
结果:
{
"shares": {
"count": 272 //share count
},
"likes": {
"data": [
],
"paging": {
},
"summary": {
"total_count": 3453 //like count
}
},
"comments": {
"data": [
],
"paging": {
},
"summary": {
"total_count": 255 //comment count
}
}
}
回答by Shubham Kumar
You can use facebook graph api like https://graph.facebook.com/?ids=http://mycodingtricks.com
and it will return a json code like
您可以使用 facebook graph api 之类的https://graph.facebook.com/?ids=http://mycodingtricks.com
,它会返回一个 json 代码,例如
{
"http://mycodingtricks.com":{
"id":"http://mycodingtricks.com",
"shares":1
}
}
I have developed my own php script on which you can all social count using that api. http://mycodingtricks.com/share/social.php?url=YOUR-URL-HEREand it will return data like:
我开发了自己的 php 脚本,您可以使用该 api 进行所有社交计数。http://mycodingtricks.com/share/social.php?url=YOUR-URL-HERE它将返回如下数据:
{
"facebook":[
{
"share_count":1,
"like_count":0,
"comment_count":0,
"total_count":1,
"click_count":0,
"comments_fbid":567687199998199,
"commentsbox_count":0
}
],
"googleplus":10,
"twitter":3,
"buffer":0,
"pinterest":0,
"stumblupon":1,
"reddit":"<html><body><h1>403 Forbidden<\/h1>\nRequest forbidden by administrative rules.\n<\/body><\/html>\n",
"linkedin":0
}
But if you wants to use on your own Here is a complete article about how to count facebook share,like and all. http://mycodingtricks.com/php/2-ways-to-count-facebook-likes-shares-and-comments-using-php/
但如果你想自己使用 这里有一篇关于如何计算 facebook 分享、点赞和所有的完整文章。http://mycodingtricks.com/php/2-ways-to-count-facebook-likes-shares-and-comments-using-php/
回答by Kevin
FQL is now depreciated. Here's how to do it using the 2.x API:
FQL 现在已折旧。以下是使用 2.x API 的方法:
get /1000076132681/posts?limit=3&fields=object_id,likes.summary(true),comments.summary(true)
This results in the xml, for example:
这将导致 xml,例如:
"summary": {
"total_count": 80
}
And in case you need the larger-size picture url as well, check out
如果您还需要更大尺寸的图片网址,请查看
?fields=full_picture,attachments