我用fbconsole在Facebook上授权。在
import fbconsole
fbconsole.APP_ID = '1234567890'
fbconsole.AUTH_SCOPE = ['publish_stream', 'publish_checkins', 'read_stream', 'offline_access']
fbconsole.authenticate()
newsfeed = fbconsole.get('/me/home', {'fields':'from,name,description,message'})
newsfeedData = newsfeed["data"]
for status in newsfeedData:
print status['from']['name'];
print status['created_time'];
#print status['name']
print status['message']
#print status.encode("utf-8")
print('##############################################################################')
status['from']['name']
显示朋友的名字,但是status['message']
显示keyror。如果'status'
是字典类型并且有'message'
键,我如何从Facebook打印新闻???在'name'
键上打印时也出现了相同的错误。在
您可以使用python的(try,except)块来解决这个问题。 例如
有时没有“名称”和“消息”值,在这种情况下,facebook不会在响应中包含它们。这可能是它抛出错误的原因。我想你应该检查一下钥匙是否存在。但老实说,我不知道如何用Python实现它。在
相关问题 更多 >
编程相关推荐