What is supposed to be the redirect_uri when getting access token in facebook app?

user1004404 picture user1004404 · Oct 20, 2011 · Viewed 49k times · Source
$token_url = "https://graph.facebook.com/oauth/access_token?client_id="
    . $app_id . "&redirect_uri=" . urlencode($my_url) 
    . "&client_secret=" . $app_secret 
    . "&code=" . $code;

What is supposed to be the redirect_uri? I tried using this

'https://graph.facebook.com/oauth/authorize?client_id='.$app_id.'&
redirect_uri='.urlencode($canvas_page).'&scope=email,read_stream,publish_stream';

but it returned with this error

{
   "error": {
      "message": "Error validating verification code.",
      "type": "OAuthException"
   }
}

Need help, Thanks in advance.

Answer

Robin picture Robin · Oct 20, 2011

First i will answer what your Redirect Url should be

Go to your Facebook application dashboard

https://developers.facebook.com/apps

Select you application from the accordion menu to the left of the page. enter image description here

There is a Value for Canvas URL(here it is 'http://localhost:7124' which point to a local server. )

The redirect url must be a url within this url(site). ie something like 'http://localhost:7124/home.aspx' or 'http://localhost:7124/main/home.aspx'


To get an access token follow the below steps

Issue a request to

https://www.facebook.com/dialog/oauth?client_id=CLIENT_ID&redirect_uri=REDIRECT_URL&scope=read_stream

This will provide you with a user authentication code(CODE) to denote that the user is signed in.

Then with this code issue a request to

https://graph.facebook.com/oauth/access_token?client_id=CLIENT_ID&redirect_uri=REDIRECT_URL&client_secret=APP_SECRET&code=CODE

which will provide you the access token in the format access_token=ACCESSTOKEN to the redirect url you have specified.

NOTE: Redirect Url must be a path inside the Canvas Url of the Facebook application and these requests should be submitted from the same domain pointed by the Canvas Url