What permission(s) do I need to read the names of the users who posted to a Facebook page?

醉酒当歌 提交于 2019-12-11 10:33:24

问题


I want to write a Python script that reads the names of the Facebook users who wrote a message on my Facebook Page.

I'm using the facebook-sdk Python library. The lines

graph = facebook.GraphAPI(page_access_token)
profile = graph.get_object(profile_id)
posts = graph.get_connections(profile['id'], 'feed')
print(posts['data'][0]['message'])
print(posts['data'][0]['from']['name'])

work fine when I use a short-lived access token retrieved by just copying it from the Graph API explorer.

But when I generate a never-expiring page access token (read here), there is an error in the last line where the Python script wants to retrieve the name. (KeyError: 'from')

So how do i set the right permissions? The access token has user_about_me, user_posts, read_page_mailboxes, manage_pages, publish_pages, public_profile permissions, but it still doesn't work. Maybe I did something wrong setting up the app I created to retrieve a new access token?

Or maybe this isn't a permissions issue after all? (See my previous question.)


回答1:


You need to specify the fields you want to retrieve manually if you're using v2.4 or higher. Unfortunately this is not documented in the project you're using:

posts = graph.get_connections(profile['id'], 'feed', 'fields=id,message,from')

should work I guess according to https://github.com/pythonforfacebook/facebook-sdk/blob/master/facebook/init.py#L117



来源:https://stackoverflow.com/questions/33280865/what-permissions-do-i-need-to-read-the-names-of-the-users-who-posted-to-a-face

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!