需要帮助解析Dict与facebook图形api

2024-04-27 03:17:25 发布

您现在位置:Python中文网/ 问答频道 /正文

晚上好,我一直在努力解析这个json,它看起来很容易,但是,最后几行,围绕着comments变量,我唯一能做的就是做一个for循环并输出所有的数据,我希望所有的数据都像“who”和“post”变量的结果。。。只分析了注释。。。谢谢你的帮助。。。在

import facebook
token = "valid access token"
graph = facebook.GraphAPI(token)
# pages = ['Shitty']
profile = graph.get_object("55555555555555555")
# this line would connect us to the facebook profile

whom = graph.get_connections("me", connection_name="feed", fields="from")
for who in whom['data']:
    print who['from']['name']

posts = graph.get_connections(id='me', connection_name="feed")
for post in posts['data']:
    print post['message']

comments = graph.get_connections('me', connection_name="feed",   fields="comments")
for comment in comments['data']:
    print comment

下面是我运行上述命令时得到的结果。。。在

^{pr2}$

Tags: nameintokenfordatagetfacebookfeed