简体   繁体   English

如何在Python中使用facebook SDK获取facebook帖子的所有评论?

[英]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.

相关问题 我可以在Python中使用facebook sdk获得喜欢,分享和评论的帖子总数吗? - Can I get the total count of a post likes, shares and comments using facebook sdk in Python? 使用Python的Facebook API。 如何打印所有帖子的评论? - Facebook API using Python. How to print out comments from ALL post? 我如何从Facebook Python SDK中获取Facebook帖子与Facebook状态 - How can I get a facebook post vs a facebook status from the facebook python sdk Python:使用facebook-sdk获取所有个人资料图片的列表 - Python: Get list of all profile pictures using facebook-sdk 如何使用facebook-sdk python在im成员的facebook组中发布 - how to post in facebook group that's im member on it using facebook-sdk python 如何通过Facebook OpenGraph检索所有帖子评论/喜欢 - How to retrieve all post comments/likes via Facebook OpenGraph 如何从 facebook 直播 stream 或帖子中抓取/获取评论? - How to scrape/get comments from facebook live stream or post? 如何使用 Python 获取 Facebook 上帖子的点赞数? - How to get the number of likes for a post on Facebook using Python? 如何使用 Python 从 Facebook 评论插件中获取文本? - How to get text from Facebook comments plugin with Python? 从 AdsInsights on Python Facebook SDK 获取所有字段 - Get all fields from AdsInsights on Python Facebook SDK
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM