需要帮助使用facebook graph api解析Dict

时间:2016-12-11 01:33:18

标签: python facebook facebook-graph-api-v2.0

晚上好,我一直在努力解析这个json,看起来很容易,然而,最后几行,在comments变量周围,我唯一能做的就是做一个for循环并输出所有数据,我希望所有的数据都像'"谁的"和"发布"变量结果......仅仅根据评论进行了解析......感谢您的帮助...

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

以下是我运行上述命令时得到的结果......

Davy Wyatt
Johnathan Tate
Jason Owens
Cuzzo keep it pushing
We READY!!!
Hello World
What's up man?

{u'id': u'122457118238072_141638009653316'}
{u'id': u'122457118238072_141637659653351'}
{u'id': u'1924167861201761_1924171591201388'}
{u'id': u'122457118238072_141458699671247'}
{u'id': u'122457118238072_141081529708964',  u'data': [{u'created_time':   u'2016-12-10T14:30:53+0000', u'message': u"What's good big homie?", u'from':     {u'name': u'JasonOwens', u'id': u'10157863582670223'}, u'id': u'141081529708964_141449913005459'}, {u'created_time': u'2016-12-10T18:09:00+0000', u'message': u"hmm, so posts have comments, with messages, with comments and messages within them.  That's quite confusing...", u'from':     {u'name': u'Jason Owens', u'id': u'10157863582670223'}, u'id':     u'141081529708964_141647769652340'}]}}
{u'id': u'122457118238072_141072773043173'}
{u'id': u'122457118238072_139707389846378'}

0 个答案:

没有答案