繁体   English   中英

在FB.ui中使用方法permissions.request重定向uri无法正常工作

[英]In FB.ui with method permissions.request redirect uri not working properly

嗨,我最近首先修改了我的应用程序,它只需要基本信息。 用户的权限,但现在我也希望流发布权限。 因此,我在索引页面上检查是否未授予用户流发布权限,我只向他显示权限对话框,如下所示:

<?php $permission = $facebook->api(array('method' =>   'users.hasAppPermission','ext_perm'=>'publish_stream','uid'=> $uid));
   if($permission != '1')
   {
    echo "<script type='text/javascript'>

                var dialog = {
                    method: 'permissions.request',
                    perms: 'publish_stream'
                };  

            FB.ui(dialog,null);
        </script>";
   }
?>

此代码正确显示了权限框,但问题是,当用户授予权限时,他将重定向到我的画布url(服务器页面上的URL),而不是画布页面(即http://apps.facebook.com/xyz )上。 为了解决这个问题,我为它添加了redirect_uri

   var dialog = {
       method: 'permissions.request',
       perms: 'publish_stream',
       redirect_uri: 'http://apps.facebook.com/xyz'
   };

但仍然无法正常工作。

请帮我如何解决这个问题。

尝试以下方法:

<?php
$loginUrl = $facebook->getLoginUrl(array(
    "scope" => "publish_stream",
    "redirect_uri" => "http://apps.facebook.com/xyz"
));

$isGranted = $facebook->api(array(
    "method"    => "users.hasAppPermission",
    "ext_perm"   => "publish_stream",
    "uid"       => $uid /* The user ID of the user whose permissions
                         * you are checking. If this parameter is not
                         * specified, then it defaults to the session user.
                         */
));
if($isGranted !== "1")
    echo("<script> top.location.href='" . $loginUrl . "'</script>");
?>

您也可以使用FQL检查许可。 有关更多信息,请参见此处


更新:
Facebook引入了权限连接,现在可以使用它代替旧的REST API:

$permissions = $facebook->api("/me/permissions");
if( array_key_exists('publish_stream', $permissions['data'][0]) ) {
    // Permission is granted!
    // Do the related task
    $post_id = $facebook->api('/me/feed', 'post', array('message'=>'Hello World!'));
} else {
    // We don't have the permission
    // Alert the user or ask for the permission!
    header( "Location: " . $facebook->getLoginUrl(array("scope" => "publish_stream")) );
}

暂无
暂无

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

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