0

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.

Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
Adam
  • 2,948
  • 10
  • 43
  • 74

1 Answers1

0

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
Sahil Mittal
  • 20,697
  • 12
  • 65
  • 90
  • What do you mean by "once you've authorized the app and call USER_ID/feed to post", how do I do that? – Adam Sep 10 '13 at 21:37
  • Do you mean I should go to 'Graph API Explorer' and generate something? I am totally lost. Please clarify. – Adam Sep 11 '13 at 00:28
  • In the question you said you were able to post on your wall and you just want to post even if the user is offline, right? If so, this means that u've authorized your app to publish on your behalf. Now, you can use the APP_ACCESS_TOKEN instead of USER_ACCESS_TOKEN with the same api call you are doing right now. To get the APP_ACCESS_TOKEN use the above code OR (app_id|app_secret) OR directly from here (https://developers.facebook.com/tools/access_token/). Hope you got the things now. – Sahil Mittal Sep 11 '13 at 06:12