![](/img/trans.png)
[英]Can I get the total count of a post likes, shares and comments using facebook sdk in Python?
[英]How to get all comments of a facebook post using facebook SDK in Python?
我想獲得facebook帖子的所有評論。 我們可以通過在Api調用中傳遞limit()
來提取注釋但是我們如何知道限制? 我需要所有評論。
https://graph.facebook.com/10153608167431961?fields=comments.limit(100).summary(true)&access_token=LMN
通過使用這個
data = graph.get_connections(id='10153608167431961', connection_name='comments')
我收到的評論很少。 如何獲得帖子的所有評論?
編輯
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)
它給出了錯誤
KeyError:'評論'
您需要實現分頁以獲取所有/更多注釋: https : //developers.facebook.com/docs/graph-api/using-graph-api/#paging
通常,這是通過“遞歸函數”完成的,但是您必須記住,如果有很多注釋,您可能會達到API限制。 最好只按需加載更多評論。
JavaScript示例: facebook javascript API中的分頁如何工作?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.