目前,我正在使用https://github.com/pythonforfacebook/facebook-sdk
不久前我刚捡到蟒蛇。
我需要做的:检索特定Facebook页面的帖子。
示例:
在Facebook图形资源管理器API中,以沃尔玛为例
/v2.2/walmart?fields=posts{message}
结果就是我所需要的。
我有什么
遵循post.py实例的示例
targetProfile = 'walmart'
graph = facebook.GraphAPI(key)
profile = graph.get_object(targetProfile)
posts = graph.get_connections(profile['id'], 'posts')
print posts['data']
在使用有效的访问键等运行上述代码之后,它似乎打印出了用户的评论/帖子,但我只需要沃尔玛的帖子。有人能告诉我我应该做什么,或者我做错了什么吗?
提前感谢!
发布于 2014-11-11 05:48:48
做了一些尝试和错误之后,我找到了答案的解决方案。这可能不是最好的解决方案,但它满足了我的要求。
profile = graph.get_object(targetProfile+"/statuses")
Jstr = json.dumps(profile)
JDict = json.loads(Jstr)
for i in JDict['data']:
print "message: "+i['message']
发布于 2015-03-24 11:18:02
下面的代码段应该解决了有关为posts检索所有消息的问题,它使用面容并自行处理分页。
from facepy import GraphAPI
import json
access = '<access_token>'
graph = GraphAPI(access)
page_id= '<page_name or page_id>'
datas= graph.get(page_id+'/posts?fields=message', page=True, retry=5)
posts=[]
for data in datas:
posts.append(data)
print posts
发布于 2014-11-28 17:36:41
profile = graph.get_object(targetProfile+"/statuses") print profile['data'][0]['message']
这将返回配置文件的第一条消息,而不使用JStr和JDict var。
https://stackoverflow.com/questions/26857767
复制