我正在尝试使用图形API下载Facebook讨论。问题是:讨论位于页面中,并且采用树式方式,这意味着有两种类型的注释:“主要”注释,第一条消息和主要注释本身的“子注释”。 / p>
图表结果似乎只显示“主要”评论,而不显示子评论。以下是它返回的评论示例:
{
"id": "53526364352_1574091",
"can_remove": false,
"created_time": "2014-02-05T10:46:37+0000",
"from": {
"name": "Main commenter",
"id": "5345353"
},
"like_count": 163,
"message": "I am a main comment",
"user_likes": false
},
此主要评论的子评论没有任何链接或其他内容(并且有很多)。
有没有办法获得子评论?
答案 0 :(得分:2)
如果10101140614002197_8831228
是根评论的ID,那么您可以通过请求COMMENT_ID/comments
来检查子评论/回复。
例如:
答案 1 :(得分:1)
您可以使用字段扩展(URL中的圆括号)来获取嵌套数据
http://graph.facebook.com/{object-id}/comments?fields=id,message,comments{id,message,comments{id,message,comments}}
Nested requests (a.k.a. field expansion)
部分中的更多信息here。
答案 2 :(得分:0)
如果要遍历和展平树,可以执行以下操作:
def get_all_comments(post_or_comment_id):
next_ids = [post_or_comment_id]
results = []
while next_ids:
next_id = next_ids.pop()
comments = get_comments_from_facebook(next_id) # Facebook API call
results += comments
next_ids.extend(c["id"] for c in comments)
return results
请确保将parent
添加到API调用中,以便您可以复制树。