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

时间:2016-09-09 13:36:56

标签: python facebook facebook-graph-api

我想获得python中facebook帖子的总计数。下面的代码给出了一些喜欢帖子的人的json对象。但不是所有的。我需要总数。有可能吗?

import requests
import facebook
token=''
graph = facebook.GraphAPI(token)
lik = graph.get_connections(id='10153608167431961', connection_name='likes')
print(lik)

结果是:

  

{'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':'蒂亚戈巴尔loni'},{'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'}}}

3 个答案:

答案 0 :(得分:5)

使用此API调用:

/10153608167431961?fields=likes.limit(0).summary(true)

结果:

{
  "likes": {
    "data": [
    ],
    "summary": {
      "total_count": 13260,
      "can_like": true,
      "has_liked": false
    }
  },
  "id": "10153608167431961"
}

替代:

/10153608167431961/likes?summary=true&limit=0

结果:

{
  "data": [
  ],
  "summary": {
    "total_count": 13260,
    "can_like": true,
    "has_liked": false
  }
}

同样的评论:

/10153608167431961/comments?summary=true&limit=0

我不确定为什么它不适用于/sharedposts,它可能是一个错误,可能是出于某种原因故意。

答案 1 :(得分:1)

我知道这已经很晚了,但你可以使用洞察力指标post_story_adds_by_action_type,它会为你提供评论,喜欢和分享的明细。

试试这个:

/{object-id}/insights/post_story_adds_by_action_type

哪个应该产生类似的东西:

{'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

答案 2 :(得分:0)

graph.get_connections(id =' 10153608167431961&#39 ;, connection_name ='赞',summary =' true')

这应该给出给定帖子/馈送的总喜欢。