[英]How to get all comments of a facebook post using facebook SDK in Python?
I want to get all comments of a facebook post. 我想获得facebook帖子的所有评论。 We can extract comments by passing the
limit()
in Api call But how we know the limit? 我们可以通过在Api调用中传递
limit()
来提取注释但是我们如何知道限制? I need all comments. 我需要所有评论。
https://graph.facebook.com/10153608167431961?fields=comments.limit(100).summary(true)&access_token=LMN
By using this 通过使用这个
data = graph.get_connections(id='10153608167431961', connection_name='comments')
I am getting few comments. 我收到的评论很少。 How can I get all comments of a post?
如何获得帖子的所有评论?
Edit 编辑
import codecs
import json
import urllib
import requests
B = "https://graph.facebook.com/"
P ="10153608167431961"
f = "?fields=comments.limit(4).summary(true)&access_token="
T = "EAACb6lXwZDZD"
url = B+P+f+T
def fun(data):
nextLink = (data['comments']['paging']['next'])
print(nextLink)
for i in data['comments']['data']:
print (i['message'])
html = urllib.request.urlopen(nextLink).read()
data = json.loads(html.decode('utf-8'))
fun(data)
html = urllib.request.urlopen(url).read()
d = json.loads(html.decode('utf-8'))
fun(d)
It is giving the error 它给出了错误
KeyError: 'comments'
KeyError:'评论'
You need to implement paging to get all/more comments: https://developers.facebook.com/docs/graph-api/using-graph-api/#paging 您需要实现分页以获取所有/更多注释: https : //developers.facebook.com/docs/graph-api/using-graph-api/#paging
Usually, this is done with a "recursive function", but you have to keep in mind that you may hit API limits if there are a LOT of comments. 通常,这是通过“递归函数”完成的,但是您必须记住,如果有很多注释,您可能会达到API限制。 It´s better to load more comments on demand only.
最好只按需加载更多评论。
Example for JavaScript: How does paging in facebook javascript API work? JavaScript示例: facebook javascript API中的分页如何工作?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.