Search code examples
pythondjangofacebookfacebook-graph-apidjango-facebook

Posting to my Facebook page from my web app in production


I installed Django Facebook and I am using this method to post to a Page:

from open_facebook.api import OpenFacebook
graph = OpenFacebook("my_access_token")
graph.set('me/feed', message='hello world')

It's working on my local dev machine when I am logged in to my Facebook account. It stops working as soon as I sign out and I get this message:

OAuthException: Error validating access token: The session is invalid because the user logged out. (error code 190)

I got my access token from Graph API Explorer by passing /me/accounts

So the question, how do I make my code work on production when of course I'll not be logged in?

Please note that I'll only be posting to a Page that I own.


Solution

  • If you want to use 'me/feed' offline;

    You can use the APP Access Token, once you've authorized the app and call USER_ID/feed to post.

    Note: use user_id instead of me- me is only used when a user is in session, but you want to do the action after logout.


    To get the app access token,

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