What is supposed to be the redirect_uri when getting access token in facebook app?
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.
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
Related videos on Youtube
user1004404
Updated on November 25, 2020Comments
-
user1004404 over 3 years
$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.
-
user1004404 over 12 yearsI also tried using apps.facebook.com/myapp but same error
-
user1004404 over 12 yearsnvm, solved, the redirect_uri must be the same as the one in the authorize 1
-
-
Admin about 12 yearsHey Robin, what to do after you get access_token? I am using asp.net MVC 3.0. Point is, 'I am sitting at different domain(graph.facebook.com) not mine, so how do I make use of that?'
-
Muneeb Zulfiqar almost 8 yearsI am implementing oAuth server. Im stuck at the point at which I have to close my dialogue and send the client to redirect URI. Any help would be much appreciated.
-
old_soul_on_the_run over 6 yearsIf I have a facebook login button on URL - localhost:8080/login and when user clicks on FB login button and authorizes then I want them to land on home page at localhost:8080/home. In this scenario which URL should go into Site URL field while creating app on FB.