简体   繁体   English

无限循环Facebook画布(游戏应用程序)

[英]Infinity loop facebook canvas (Game App)

when the user "denies permissions" of my application, they are redirected back to the screen with "requests for permission", thus creating an infinite loop, which is prohibited by facebook privacy policies. 当用户“拒绝我的应用程序的权限”时,他们将通过“请求权限”重定向回屏幕,从而创建一个无限循环,这是facebook隐私策略所禁止的。 Can anyone help me fix this problem? 谁能帮我解决这个问题?

My used php code is this: 我使用的php代码是这样的:

<?php
// appsource
require_once 'facebook.php';

require_once 'appinclude.php';
    if (isset($_GET['code'])){
        header("Location: " . $canvasPage);
        exit;
    }

$fb = new Facebook(array(
    'appId' => $appid,
    'secret' => $appsecret,
    'cookie' => true
));

$me = null;
 $user = $fb->getUser();

if($user) {
    try {
        $me = $fb->api('/me');
    } catch(FacebookApiException $e) {
        error_log($e);
    }
}

if($me) {}
else {

    $loginUrl = $fb->getLoginUrl(array(
        'scope' => ''
    ));
        echo "
        <script type='text/javascript'>
        window.top.location.href = '$loginUrl';
        </script>
    ";  
    exit;
}


if(isset($_GET['signed_request'])) {
    $fb_args = "signed_request=" . $_REQUEST['signed_request'];
}


include 'spinc.php';


function ae_detect_ie(){
    if (isset($_SERVER['HTTP_USER_AGENT']) &&
    (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
            return true;    
    else        
        return false;}


?>

You can have 2 different endpoints or add special parameters in url - that will allow you understand - did user click login button already or no. 您可以有2个不同的终结点,也可以在url中添加特殊参数-这将使您理解-用户是否已单击登录按钮或是否单击了登录按钮。

See - Facebook give possibility to setup callback url after user login actions: https://developers.facebook.com/docs/php/howto/example_facebook_login/5.0.0 请参阅-Facebook提供了在用户登录操作后设置回调URL的可能性: https : //developers.facebook.com/docs/php/howto/example_facebook_login/5.0.0

So - you can modify you code to: 所以-您可以将代码修改为:

$loginUrl = $fb->getLoginUrl(
    'https://example.com/fb-callback.php',
    array('scope' => '')
);

And in "fb-callback.php" script test if user logged or no. 并在“ fb-callback.php”脚本中测试用户是否登录。 And if user not logged - just inform (show message) user that only logged users can process or something like that. 如果用户未登录-只需通知(显示消息)用户只有登录的用户才能处理或类似的操作。 So - those actions will remove infinity loop. 所以-这些动作将消除无限循环。

I edited the code, and now he seems to be more redirecting the user to the same place after denying permissions. 我编辑了代码,现在他似乎在拒绝权限后将用户重定向到同一位置。 The code looks like this: 代码如下:

 <?php
// appsource
require_once 'facebook.php';
require_once 'appinclude.php';
if( isset($_GET['code']) ){ header("Location: " . $canvasPage); exit; } elseif( isset($_REQUEST['error']) && isset($_REQUEST['error_reason']) ){ $gamePage = 'https://www.facebook.com/games/APPNAME'/?fbs=502'; header("Location: " . $gamePage);
exit; } 
$fb = new Facebook(array(
'appId' => $appid,
'secret' => $appsecret,
'cookie' => true
));
$me = null;
 $user = $fb->getUser();
if($user) {
try {
$me = $fb->api('/me');
} catch(FacebookApiException $e) {
error_log($e);
}
}
if($me) {}
else {
$loginUrl = $fb->getLoginUrl(array(
'scope' => ''
));
echo "
<script type='text/javascript'>
window.top.location.href = '$loginUrl';
</script>
";  
exit;
}
if(isset($_GET['signed_request'])) {
$fb_args = "signed_request=" . $_REQUEST['signed_request'];
}
include 'spinc.php';
function ae_detect_ie(){
if (isset($_SERVER['HTTP_USER_AGENT']) &&
(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== false))
return true;    
else        
return false;}
?>

But is that I can use the code this way? 但是我可以用这种方式使用代码吗? or you can be at odds with the platform's privacy policy? 还是您可能与该平台的隐私政策背道而驰?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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