Search code examples
djangofacebookfacebook-graph-apifandjango

How to save and refresh Facebook access token of user (admin)


I am thinking to implement Facebook Wordpress Plugin for bloggers in django (using Fandjango & Facepy).

To be specific:

The project admin/ developer will be the only person as user. So, the application need to perform /friend_id/feed calls on the admin automatically in the background.

For that all I would need is to store admin's access token and use it when ever I want..

Now, I got some problems to address:

  1. How to refresh the admin's access token when it expires automatically without admin's intervention

Actually, can we store access token (I mean securely). I somewhere read that its not possible (not sure of the information)


Solution

  • If the user authorizes this as an app, with the permissions publish_stream (to publish stories to the News Feeds of the user and their Friends) and user_likes (to have access to the pages at the user has 'liked'), you can use:

    https://graph.facebook.com/oauth/access_token?client_id=YOUR_APP_ID&client_secret=YOUR_APP_SECRET&grant_type=client_credentials

    to create an App access token. Since these do not often change, you can store it if you like, but it may be wise to make the above request each time, so that in case it does change, you are somewhat protected.

    Then, use the Graph API, JS SDK or PHP SDK to publish the story, which is quite straightforward.