Unable to get a long term access token using facebook graph api

StafHat picture StafHat · Sep 6, 2013 · Viewed 15k times · Source

I'm new to integrating facebook into the websites I'm working on and trying to get a long term access token by following the instructions here: https://developers.facebook.com/docs/facebook-login/access-tokens/ Even when using the Graph API Explorer here: https://developers.facebook.com/tools/explorer/ I enter the following and populate it with my AppID and AppSecret and current token I get when I press Get Access Token...

GET /oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}& client_secret={app-secret}& fb_exchange_token={short-lived-token}

I get the return

{ "error": "Invalid response" }

Can someone elaborate on what I might be doing wrong, or the steps in greater detail that works for you in acquiring this long term token.

I've tried to follow what's happening in this thread Facebook Page Access Tokens - Do these expire? with no more success. Any help would be greatly appreciated.

Thanks for your time and help. Cheers,

-Ryan

Answer

Sahil Mittal picture Sahil Mittal · Sep 6, 2013

You can't get the long-lived user token using the Graph API Explorer. You have to make a GET request to:

https://graph.facebook.com/oauth/access_token?
grant_type=fb_exchange_token&
client_id={app-id}& client_secret={app-secret}& fb_exchange_token={short-lived-token}

You can check it in the browser.

If you need the page access token, you can have a never expiring token. Check out the accepted answer here: What are the Steps to getting a Long Lasting Token For Posting To a Facebook Fan Page from a Server