Search code examples
facebook-sdk-4.0

Using python facebook sdk to post an update/message on facebook


Based on the instructions I got from the documentation this is my attempt at using the sdk platform and the error I get

In [5]: graph = facebook.GraphAPI(access_token=my_access_token, version="2.12")

In [6]: graph.put_object(parent_object='me', connection_name='feed',
...:                   message='Hello, world http://68.183.98.238/blog/best-floor-for-high-traffic-areas')
---------------------------------------------------------------------------
GraphAPIError                             Traceback (most recent call last)
<ipython-input-6-e8b64d6b32a8> in <module>
    1 graph.put_object(parent_object='me', connection_name='feed',
----> 2                   message='Hello, world http://68.183.98.238/blog/best-floor-for-high-traffic-areas')

~/code/envs/decomagna/lib/python3.6/site-packages/facebook/__init__.py in put_object(self, parent_object, connection_name, **data)
    190             "{0}/{1}/{2}".format(self.version, parent_object, connection_name),
    191             post_args=data,
--> 192             method="POST",
    193         )
    194

~/code/envs/decomagna/lib/python3.6/site-packages/facebook/__init__.py in request(self, path, args, post_args, files, method)
    311
    312         if result and isinstance(result, dict) and result.get("error"):
--> 313             raise GraphAPIError(result)
    314         return result
    315

GraphAPIError: Invalid OAuth access token.

enter image description here

the access token is the same one I got from facebook developer page.

It feels like I haven't provided enough verification especially to post on my behalf.


Solution

  • First of all: Posting messages to a user wall is not possible anymore, the publish_actions permission is deprecated. (https://developers.facebook.com/blog/post/2018/04/24/new-facebook-platform-product-changes-policy-updates/)

    That being said, you are probably using the "Client Token" from your screenshot, which is the wrong one. You would have to authorize your user with the required permission and use the resulting User Token instead.