使用Facebook API(python)检索Facebook页面的帖子 [英] Retrieve post of a Facebook page using Facebook API (python)
问题描述
当前,我正在使用 https://github.com/pythonforfacebook/facebook-sdk
不久前我刚拿起python.
I just picked up python not too long ago.
我需要做什么: 检索特定Facebook页面上的帖子.
What i need to do: Retrieve posts of a particular Facebook page.
示例:
在Facebook Graph Explorer API上,以沃尔玛为例
At Facebook Graph Explorer API, using walmart as an example
/v2.2/walmart?fields=posts{message}
结果就是我所需要的.
我有什么
以下示例来自 get_post.py示例
targetProfile = 'walmart'
graph = facebook.GraphAPI(key)
profile = graph.get_object(targetProfile)
posts = graph.get_connections(profile['id'], 'posts')
print posts['data']
使用有效的访问密钥等运行以上代码后,似乎可以打印出消费者的评论/帖子,但我只需要沃尔玛的帖子.有人能启发我应该做什么或做错了什么吗?
After running the above code with valid access key, etc., it seems to print out comments/post of consumer but I only need the posts from walmart. Can someone enlighten me as to what i should do, or what I did wrong?
提前谢谢!
推荐答案
在进行了一些反复试验之后,我找到了答案的解决方案.这可能不是最好的解决方案,但可以满足我的要求.
After doing some trial and errors, i found the solution to my answer. This might not be the best solution but it fulfill my requirement.
profile = graph.get_object(targetProfile+"/statuses")
Jstr = json.dumps(profile)
JDict = json.loads(Jstr)
for i in JDict['data']:
print "message: "+i['message']
这篇关于使用Facebook API(python)检索Facebook页面的帖子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!