简体   繁体   English

我可以在Python中使用facebook sdk获得喜欢,分享和评论的帖子总数吗?

[英]Can I get the total count of a post likes, shares and comments using facebook sdk in Python?

I want to get the total number of counts of a facebook post in python. 我想获取python中一个Facebook帖子的总数。 The code below is giving a json object of some persons who likes the post. 下面的代码提供了一些喜欢这篇文章的人的json对象。 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 Ballon {'data':[{'id':'1583767538554134','name':'ØpPö'},{'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üneytEkin'},{'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 Ballon i'}, {'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'}}} i'},{'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 ”, '游标':{ '前': '后MTU4Mzc2NzUzODU1NDEzNAZDZD', '': 'NzM5OTYzMDIyNzY2NTY2'}}}

Use this API call: 使用此API调用:

/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. 我不确定为什么它不能与/sharedposts ,这可能是一个错误,出于某些原因可能是故意的。

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. 我知道这已经很晚了,但是您可以使用见解指标post_story_adds_by_action_type ,将为您提供评论,喜欢和分享的明细。

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 https://developers.facebook.com/docs/graph-api/reference/v2.10/insights

graph.get_connections(id='10153608167431961', connection_name='likes', summary='true') graph.get_connections(id ='10153608167431961',connection_name ='likes',summary ='true')

This should give the total likes for the given post/feed. 这应该给出给定帖子/提要的总点赞数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Python中使用facebook SDK获取facebook帖子的所有评论? - How to get all comments of a facebook post using facebook SDK in Python? 我可以使用facebook SDK和python获取喜欢公开页面的粉丝的名单(姓名-电子邮件)吗? - Can I get a list (name - email) of fans who likes a public page using the facebook SDK and python? 使用Python + Facebook Graph API计算在Facebook帖子上的喜欢数 - Count likes on a Facebook post using Python+Facebook Graph API 刮 facebook 喜欢,评论和分享美丽汤 - Scraping facebook likes, comments and shares with Beautiful Soup 我如何计算总喜欢? - How can I count total likes? 如何使用 Python 获取 Facebook 上帖子的点赞数? - How to get the number of likes for a post on Facebook using Python? Python / Facebook-SDk如何获取页面上发布的照片​​的共享计数 - Python/Facebook-SDk How to get shares count for a photo posted on a page 我如何从Facebook Python SDK中获取Facebook帖子与Facebook状态 - How can I get a facebook post vs a facebook status from the facebook python sdk 使用 Tweet Parser 在 Twitter 帖子上打印喜欢、评论和分享 - Using the Tweet Parser to print likes, comments, and shares on Twitter posts 如何在 Python 中使用 PDFMiner 获取 PDF 文件的总页数? - How can I get the total count of total pages of a PDF file using PDFMiner in Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM