Facebook PHP SDK 4.0-拒绝后就无法重新授予读取权限 [英] Facebook PHP SDK 4.0 - Cannot re-ask read permissions once denied

本文介绍了Facebook PHP SDK 4.0-拒绝后就无法重新授予读取权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在要求用户提供两个读取权限(即emailuser_location)和一个写入权限(即publish_actions).以下是我用来验证用户是否已授予所有请求的权限的代码段:

I'm currently asking users for two read permissions i.e. email and user_location and one write permssion i.e. publish_actions. Following is the code snippet I'm using to verify if the user has granted all requested permissions:

    $facebook = new Facebook(APP_ID, APP_SECRET, REDIRECT_URI);

    if ( $facebook->IsAuthenticated() ) {

        // Verify if all of the scopes have been granted
        if ( !$facebook->verifyScopes( unserialize(SCOPES) ) ) {
            header( "Location: " . $facebook->getLoginURL( $facebook->denied_scopes) );
            exit;
        }
        ...
    }

Facebook是我自定义构建的类,用于包装SDK中各种类使用的登录流. IsAuthenticated()使用code get变量来检查用户是否被授权. verifyScopes()检查对SCOPES授予的权限,并将拒绝作用域的数组赋给denied_scopes属性. getLoginURL()`根据作为数组传递的权限(仅作为参数)构建登录对话框URL.

Facebook is a class I've customly built to wrap the login flow used by various classes in the SDK. IsAuthenticated() makes the use of code get variable to check if the user is authorized. verifyScopes() checks granted permissions against SCOPES and assings an array of denied scopes to denied_scopes property. getLoginURL()` builds a login-dialog URL based on permissions passed as an an array as a only paramter.

现在,问题是当用户不授予写许可权时,在这种情况下,publish_actions,将显示写许可权对话框,直到用户授予写许可权为止.但是,如果用户选择拒绝读取权限(例如email),则不会显示读取登录对话框.相反,Facebook重定向到回调URL(即REDIRECT_URI),从而创建重定向循环.

Now, the problem is when the user doesn't grant write permissions, publish_actions in this case, write permission dialog is shown until user grants the write permission. But if the user chooses to deny of the read permissions, say email, the read login dialog isn't show. Instead Facebook redirects to the callback URL (that is REDIRECT_URI) creating a redirect loop.

我正在构建的应用程序要求强制提供email,但是显然上述方法(似乎是唯一的方法)失败了.那么,是否有解决方法或替代方法来实现这一目标?还是Facebook一旦拒绝就不允许请求读取权限?

The application I'm builiding requires email to be compulsorily provided but apparently the above approach (which seems to be the only) is failing. So, is there a workaround or a alternative way to achieve this? Or Facebook doesn't allow to ask for read permissions once denied?

推荐答案

截至 2014年7月15日

As of July 15, 2014, an update has been made to the Facebook PHP SDK 4.x that allows user to re-ask the declined permissions. The function prototype of getLoginUrl() now looks like this.

public function getLoginUrl($redirectUrl, $scope = array(), $rerequest = false, $version = null)

因此,要重新询问被拒绝的权限,我们将执行以下操作:

So, to re-ask declined permissions we'd do something like this:

<?php
// ...

$helper = new FacebookRedirectLoginHelper();

if ($PermissionIsDeclined) {
    header("Location: " . $helper->getLoginUrl( $redirect_uri, $scopes, true );
    exit;
}

// ....
?>

这篇关于Facebook PHP SDK 4.0-拒绝后就无法重新授予读取权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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