gpt4 book ai didi

python - 使用 Facebook API 检索 Facebook 页面的帖子 (python)

转载 作者:行者123 更新时间:2023-12-01 04:58:20 24 4
gpt4 key购买 nike

目前,我正在使用https://github.com/pythonforfacebook/facebook-sdk

我不久前刚刚开始学习Python。

我需要做什么:检索特定 Facebook 页面的帖子。

示例:

在 Facebook Graph Explorer API 中,以 walmart 为例

/v2.2/walmart?fields=posts{message}

结果就是我需要的。

我有什么

按照 the get_post.py example 中的示例

targetProfile = 'walmart'
graph = facebook.GraphAPI(key)
profile = graph.get_object(targetProfile)
posts = graph.get_connections(profile['id'], 'posts')

print posts['data']

使用有效的访问 key 等运行上述代码后,它似乎打印出消费者的评论/帖子,但我只需要来自沃尔玛的帖子。有人可以告诉我我应该做什么,或者我做错了什么吗?

提前致谢!

最佳答案

经过一些尝试和错误后,我找到了答案的解决方案。这可能不是最好的解决方案,但它满足我的要求。

profile = graph.get_object(targetProfile+"/statuses")

Jstr = json.dumps(profile)
JDict = json.loads(Jstr)

for i in JDict['data']:
print "message: "+i['message']

关于python - 使用 Facebook API 检索 Facebook 页面的帖子 (python),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26857767/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com