Search code examples
phpfacebookfacebook-graph-apiaccess-token

How to get the access token?


When a user open the app for the first time the permissions page comes back with a code that i'm using here https://graph.facebook.com/oauth/access_token?client_id=ID&redirect_uri=MY_URL&client_secret=SECRET&code=CODE to get the access token.

If is the first time that the user open the app it works. If is not the first time i can't get an updated token. I've tried saving the code for each user that joins, but it changes and old codes can't provide an access token. I've also tried to save the token but it expire too. I also prefere to don't use the offline_access permission.

Thanks in advance for the help ;)


Solution

  • that's right, the access token has an expiration date, and it is issued for short time.

    try this thread: What is the correct way to refresh Facebook OAuth2 access token after it expires?

    also, you can use client side authentication with the help of the javascript api. use the official docs: Facebook Authentication and the js sdk auth methods, such as: Facebook Javascript getAuthResponse Function