Facebook getLoginUrl和next参数无法正常工作 [英] Facebook getLoginUrl and next parameter doesn't work properly

查看:111
本文介绍了Facebook getLoginUrl和next参数无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码:

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

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

I need to redirect the user to apps URL of my application when authetication is successfull but it always redirect to my redirect_uri page.

如何解决?

谢谢。

推荐答案

您必须更改此网址才能将应用程序重定向到身份验证后的所需位置。

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

或您可以执行此操作

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

First of all, you don't have to edit PHP SDK, below is the sample for authenticating the user and then redirecting to your landing page,

确保更换:

您的APP -ID-HERE与您的Facebook应用程序ID,

YOUR-APP-ID-HERE with Your facebook application id,

您的APP-API秘密 - 与您的Facebook应用程序密钥

YOUR-APP-API-SECRET-HERE with Your facebook application secret key

您的REDIRECT-URL-HERE与您的着陆页URL

YOUR-REDIRECT-URL-HERE with Your landing page 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>");
    }

?>

如果要获取扩展权限,则只需在登录名中添加另一个scope参数即可,例如:

If you want to get extended permissions, then simply add another "scope" parameter to the login url, ex:

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

这篇关于Facebook getLoginUrl和next参数无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆