[英]Facebook PHP SDK - 'next' param work with getLogoutUrl but don't with getLoginURL()
[英]Facebook getLoginUrl and next parameter doesn't work properly
我的代碼:
$url = $fb->getLoginUrl(array('scope'=>'email','next'=>'http://apps.facebook.com/APPID/'));
echo "<script> top.location=\"".$url."\"; </script>";
身份驗證成功后,我需要將用戶重定向到我的應用程序的應用程序URL,但它總是重定向到我的redirect_uri頁面。
我該如何解決?
謝謝。
驗證后,您必須更改此URL才能將應用重定向到所需的位置。
或者您可以這樣做
首先,您無需編輯PHP SDK,以下是用於驗證用戶身份然后重定向到您的登錄頁面的示例,
確保更換:
YOUR-APP-ID-HERE與您的Facebook應用程序ID,
YOUR-APP-API-SECRET-HERE與您的facebook應用程序密鑰
您的重定向頁面網址(帶有您的着陸頁網址)
<?php
// Requires Facebook PHP SDK 3.0.1: https://github.com/facebook/php-sdk/
require ('facebook.php');
define('FACEBOOK_APP_ID',"YOUR-APP-ID-HERE");
define('FACEBOOK_SECRET',"YOUR-APP-API-SECRET-HERE");
define('REDIRECT_URI',"YOUR-REDIRECT-URL-HERE");
$user = null;
$facebook = new Facebook(array(
'appId' => FACEBOOK_APP_ID,
'secret' => FACEBOOK_SECRET,
'cookie' => true
));
$user = $facebook->getUser(); // Get the UID of the connected user, or 0 if the Facebook user is not connected.
if($user == 0) {
// If the user is not connected to your application, redirect the user to authentication page
/**
* Get a Login URL for use with redirects. By default, full page redirect is
* assumed. If you are using the generated URL with a window.open() call in
* JavaScript, you can pass in display=popup as part of the $params.
*
* The parameters:
* - redirect_uri: the url to go to after a successful login
* - scope: comma separated list of requested extended perms
*/
$login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI));
echo ("<script> top.location.href='".$login_url."'</script>");
} else {
// if the user is already connected, then redirect them to landing page or show some content
echo ("<script> window.location.href='".REDIRECT_URI."'</script>");
}
?>
如果您想獲得擴展權限,只需在登錄URL中添加另一個“ scope”參數,例如:
$login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI,'scope' => 'comma-separated-list-of-requested-extended-perms'));
在應用設置頁面中更改重定向uri。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.