Reputation: 905
I want to get the total number of counts of a facebook post in python. The code below is giving a json object of some persons who likes the post. But not all. I need total counts. Is it possible?
import requests
import facebook
token=''
graph = facebook.GraphAPI(token)
lik = graph.get_connections(id='10153608167431961', connection_name='likes')
print(lik)
Result is :
{'data': [{'id': '1583767538554134', 'name': 'Øp Pö'}, {'id': '120568968399628', 'name': 'William Anthony Christo'}, {'id': '699615593474341', 'name': 'Anum Rabani'}, {'id': '290360191169562', 'name': 'রফিকুল ইসলাম তৌফিক'}, {'id': '119195851825867', 'name': 'Anant Gharte'}, {'id': '1584033738513309', 'name': 'Miguel Gates'}, {'id': '170725429957788', 'name': 'Rahmatullah Kazimi'}, {'id': '165244040549022', 'name': 'Jose Marques'}, {'id': '553277864818751', 'name': 'Shubham Kumar'}, {'id': '177910112626556', 'name': 'Rajesh Singh'}, {'id': '10206027408500948', 'name': 'Cüneyt Ekin'}, {'id': '134409193615843', 'name': 'Moazzem Hossain'}, {'id': '1452911201684073', 'name': 'Sohail Noori'}, {'id': '706685776074740', 'name': 'Man Muet'}, {'id': '1655289584790642', 'name': 'Emeghara Lucky Kelechi'}, {'id': '10205877189481867', 'name': 'Danielle Oliver Solomon'}, {'id': '511315079054021', 'name': 'Ajay Kumar'}, {'id': '659773750764822', 'name': 'Tiago Balloni'}, {'id': '385284718315460', 'name': 'Ivica Herman'}, {'id': '394871897335035', 'name': 'Zubayer Hassan'}, {'id': '532960883548514', 'name': 'Mohan Rathod'}, {'id': '373452456160618', 'name': 'Jeevajohthy Pramulu Naidu'}, {'id': '803092719700936', 'name': 'Patricia Ann Harris'}, {'id': '960692997327631', 'name': 'Osama Ozy'}, {'id': '739963022766566', 'name': 'Abdalrhman Selim'}], 'paging': {'next': 'https://graph.facebook.com/v2.1/10153608167431961/likes?access_token=EAACEdEose0cBAJZC5cI5OJZC6l6XZATLGsBjutHdQyvqEs4yQk7HejvKNAHqLwdNgANtMdvnGAekUo7Mx10u8K2MydmOCNNzEDmPAL3kTQITKTYIwwD1ZCNTjpLtSnZATTiW0xWrnaFbjJomXKQUnkMpF3ZCBqh6WYMixkh5tuhQZDZD&limit=25&after=NzM5OTYzMDIyNzY2NTY2', 'cursors': {'before': 'MTU4Mzc2NzUzODU1NDEzNAZDZD', 'after': 'NzM5OTYzMDIyNzY2NTY2'}}}
Upvotes: 0
Views: 4716
Reputation: 36
I know this is pretty late, but you can use the insights metric post_story_adds_by_action_type
, which will give you a breakdown of comments, likes, and shares.
Try this:
/{object-id}/insights/post_story_adds_by_action_type
Which should yield something like:
{'description': 'Lifetime: The number of unique people who created a story about your Page post by interacting with it. (Unique Users)',
'id': {object-d}/insights/post_story_adds_by_action_type_unique/lifetime',
'name': 'post_story_adds_by_action_type_unique',
'period': 'lifetime',
'title': 'Lifetime Talking About This (Post) by action type',
'values': [{'value': {'comment': 10, 'like': 20, 'share': 30}}]}]}
https://developers.facebook.com/docs/graph-api/reference/v2.10/insights
Upvotes: 1
Reputation: 11
graph.get_connections(id='10153608167431961', connection_name='likes', summary='true')
This should give the total likes for the given post/feed.
Upvotes: 0
Reputation: 73984
Use this API call:
/10153608167431961?fields=likes.limit(0).summary(true)
Result:
{
"likes": {
"data": [
],
"summary": {
"total_count": 13260,
"can_like": true,
"has_liked": false
}
},
"id": "10153608167431961"
}
Alternative:
/10153608167431961/likes?summary=true&limit=0
Result:
{
"data": [
],
"summary": {
"total_count": 13260,
"can_like": true,
"has_liked": false
}
}
The same for comments:
/10153608167431961/comments?summary=true&limit=0
I am not sure why it does not work with /sharedposts
, it may be a bug, it may be intentional for some reason.
Upvotes: 5