gpt4 book ai didi

php - Facebook getLoginUrl 和下一个参数无法正常工作

转载 作者:行者123 更新时间:2023-12-01 09:05:10 25 4
gpt4 key购买 nike

我的代码:

$url = $fb->getLoginUrl(array('scope'=>'email','next'=>'http://apps.facebook.com/APPID/'));
echo "<script> top.location=\"".$url."\"; </script>";

当身份验证成功时,我需要将用户重定向到我的应用程序的应用程序 URL,但它总是重定向到我的 redirect_uri 页面。

我该如何解决?

谢谢。

最佳答案

您必须更改此 URL 才能在身份验证后将您的应用重定向到您想要的位置。

You have to change this URL to redirect you app where you want after authentication.

或者你可以这样做

首先,您不必编辑 PHP SDK,下面是验证用户然后重定向到您的着陆页的示例,

确保更换:

YOUR-APP-ID-HERE 和你的 facebook 应用程序 ID,

YOUR-APP-API-SECRET-HERE 和您的 facebook 应用程序 key

YOUR-REDIRECT-URL-HERE 和您的着陆页 URL

<?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 中添加另一个“范围”参数,例如:

$login_url = $facebook->getLoginUrl($params = array('redirect_uri' => REDIRECT_URI,'scope' => 'comma-separated-list-of-requested-extended-perms'));

关于php - Facebook getLoginUrl 和下一个参数无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9386752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com