繁体   English   中英

Facebook 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才能将应用重定向到所需的位置。

验证后,您必须更改此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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM