Python,facebook-sdk graphAPI返回空数据集

时间:2018-03-22 21:13:25

标签: python facebook-graph-api

我编写了一个python脚本来获取用户的提要信息。

try:
    # Init graphAPI with short-lived token
    graph = facebook.GraphAPI(access_token_fb)
    # Exchange short-lived-token to long-lived
    long_token = graph.extend_access_token(app_id, app_secret)
    print(long_token)
    # Init graphAPI with long-lived token
    graph = facebook.GraphAPI(long_token['access_token'])
    profile = graph.get_object("me")
    print('profile : '+str(profile))
    posts=graph.get_connections(profile['id'],'feed')
    print(posts['data'])
    return posts
except facebook.GraphAPIError:
    return None

无论是尝试检索帖子还是Feed,我都会获得空数据集。我使用Graph API资源管理器中的访问令牌来获取Feed,它确实返回了数据,因此用户访问令牌也具有权限。脚本中可能出现什么问题?我只想把所有帖子贴在我的墙上。

2 个答案:

答案 0 :(得分:0)

问题在于您传递的内容get_object()。您应该传递类似profile = graph>get_object(id=MY_USER_ID)的内容,其中MY_USER_ID是表示您Facebook唯一用户ID的字符串。

希望这有帮助!

答案 1 :(得分:0)

I got it working, was using the wrong application’s access token. Provided permissions to the app and got the results back.