How to programmatically post to my wall on Facebook?

I am trying to make a simple program to post something on my wall in Fcebook in Python. I tried using this example from a pythonforfacebook :

import facebook oauth_access_token = "****" graph = facebook.GraphAPI(oauth_access_token) me = "****" profile = graph.get_object(me) graph.put_object(me, "feed", message="I am writing on my wall!") 

I tried to go to the developer center and make an application. For "Choose how your application integrates with Facebook," I selected "Website with Facebook Login" (I actually do not have a website, I just have a program that should post to my facebook wall, but this is the closest an option that matches What I want to do ...).

However, when I run this, it says:

 $ python a.py Traceback (most recent call last): File "a.py", line 7, in <module> graph.put_object(me, "feed", message="I am writing on my wall!") File "/usr/lib64/python2.7/site-packages/facebook.py", line 140, in put_object post_args=data) File "/usr/lib64/python2.7/site-packages/facebook.py", line 298, in request raise GraphAPIError(response) facebook.GraphAPIError: (#200) The user hasn't authorized the application to perform this action 

How can I log in as a user and authorize my application? Am I even right? I don’t actually have a website, I just have a program, for the website field I literally entered β€œ http://google.com ” and it worked.

+6
source share
2 answers

I earned by receiving a new token with permissions for publishing on my wall (in particular, the permission "publish_actions"). I did this using the Graph API Explorer , selecting my application from the drop-down menu, clicking "Get Access Token" and checking "publish_actions". The only problem is that the token expires in an hour.

+3
source

You must allow the user permission publish_action / publish_stream to publish on the wall.


  • If your only task is to place on the wall / get basic information; you can use APP Access Token instead of a user access token to perform an action after authorizing the application. To get access token for applications, you can use uuse -

     GET /oauth/access_token? client_id={app-id} &client_secret={app-secret} &grant_type=client_credentials 

    Or right from here . But do not do it hard in your application (for security reasons)

  • Or, if you want to perform other actions also on behalf of the user, you can extend the user token up to 2 months. Read more here for more details.

+2
source

Source: https://habr.com/ru/post/953348/