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

1

25
$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.

Tarkany answered 20/10, 2011 at 3:35 Comment(2)
I also tried using apps.facebook.com/myapp but same errorTarkany
nvm, solved, the redirect_uri must be the same as the one in the authorize 1Tarkany
N
17

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

Noaccount answered 20/10, 2011 at 11:16 Comment(3)
Hey 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?'Genista
I 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.Upandcoming
If 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.Inmesh

© 2022 - 2024 — McMap. All rights reserved.