How to let Facebook Login button redirect to a particular URL ?
Facebook login is a popular way for web developer these days to capture user data and at the same time login the user to the protected part of their website. A common question about what happen next after authenticating the user is :
Is there a way to redirect to a URL after the user successfully logs in?
Yes, you can redirect your user to a particular page after authentication by including the redirect_uri
parameter.
$params = array(
'scope' => 'read_stream, friends_likes',
'redirect_uri' => 'https://www.myapp.com/post_login_page'
);
$loginUrl = $facebook->getLoginUrl($params);
In the event, that you get this error message returned :
"error": {
"message": "Error validating verification code.",
"type": "OAuthException"
}
Go to https://developers.facebook.com/apps
Make sure that the Canvas URL is set up correctly and the redirect_uri
must be one of the URI under the Canvas URL
For example, your canvas URL value is set to http://www.myapps.com
, the redirect_uri
must be http://www.myapps.com/something or http://www.myapps.com/somecontroller and NOT http://www.someoneelseapps.com/something
Hope this tutorial can be useful.
Reference :
https://developers.facebook.com/docs/reference/php/facebook-getLoginUrl
See also : Facebook PHP getUser() returns 0
By Adam Ng
IF you gain some knowledge or the information here solved your programming problem. Please consider donating to the less fortunate or some charities that you like. Apart from donation, planting trees, volunteering or reducing your carbon footprint will be great too.
Advertisement
Tutorials
+9.7k PHP : Convert(cast) bigInt to string
+9.3k Golang : Generate 403 Forbidden to protect a page or prevent indexing by search engine
+4.6k Python : Print unicode escape characters and string
+10.8k Golang : Determine if time variables have same calendar day
+13.1k Golang : ROT47 (Caesar cipher by 47 characters) example
+8.2k Golang : Temperatures conversion example
+46.2k Golang : How to convert JSON string to map and slice
+8.2k Golang : does not implement flag.Value (missing Set method)
+16.5k Golang : Put UTF8 text on OpenCV video capture image frame
+3.9k JQuery : Calling a function inside Jquery(document) block
+15.7k Golang : Find file size(disk usage) with filepath.Walk
+6.2k Golang : Check if one string(rune) is permutation of another string(rune)