Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 554
user1004404 Avatar asked Oct 20 '11 03:10

user1004404


People also ask

What is the purpose of Redirect_uri?

A redirect URI, or reply URL, is the location where the authorization server sends the user once the app has been successfully authorized and granted an authorization code or access token.

How do I know if my Facebook access token has expired?

Basically, you can subscribe to updates that will tell you 1) if the user removed the app or 2) if the user removed permissions. You could use this to store the current permissions of the faceboook user. This way, if the user removed your app you would know that the access token is expired.


1 Answers

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

like image 50
Robin Avatar answered Oct 02 '22 12:10

Robin