Python facebook-sdk: retrieving names of users who posted a message on a page

倾然丶 夕夏残阳落幕 提交于 2019-12-11 20:23:15

问题


I want to use the Python facebook-sdk library to retrieve the names of the persons who posted a message on a Facebook page I created.

This is an example, returned by the Graph API explorer:

{
"feed": {
  "data": [
  {
    "from": {
      "name": "Ralph Crützen",
      "id": "440590514975673"
    },
    "message": "Nog een test.",
    "created_time": "2015-10-17T19:33:30+0000",
    "id": "649463214822976_649745285127205"
  },
  {
    "from": {
      "name": "Ralph Crützen",
      "id": "440590514975673"
    },
    "message": "Testing!",
    "created_time": "2015-10-16T20:44:17+0000",
    "id": "649463214822976_649492455153388"
  },
... etc ...

But when I use the following Python code...

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

...only the message value is printed. Printing the name of the person who posted the message gives the error:

    print(posts['data'][0]['from']['name'])
KeyError: 'from'

At first, I thought that I needed the read_page_mailboxes permission. To use this permission, it has to be approved by Facebook, so I submitted a request. But Facebook replied: "You don't need any additional permissions to post to Pages or blogs that you administer. You only need to submit your app for review if your app will use a public-facing login."

So what exactly is the reason I can't retrieve the from data from the messages feed? (While reading it from the Graph API explorer works fine...)

Btw, I'm using a page access token which never expires. I generated this token the way it's described here.

来源:https://stackoverflow.com/questions/33244676/python-facebook-sdk-retrieving-names-of-users-who-posted-a-message-on-a-page

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