【问题标题】:In FB.ui with method permissions.request redirect uri not working properly在具有方法 permissions.request 重定向 uri 的 FB.ui 中无法正常工作
【发布时间】:2011-02-28 09:51:00
【问题描述】:

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

<?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 facebook iframe fbjs facebook-php-sdk


    【解决方案1】:

    试试这个:

    <?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 来检查权限。可以在here 找到更多相关信息。


    更新:
    Facebook 引入了 permissions 连接,现在是 it can be used,而不是旧的 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")) );
    }
    

    【讨论】:

      猜你喜欢
      • 2011-12-22
      • 1970-01-01
      • 2017-09-23
      • 2015-08-09
      • 2014-07-01
      • 2015-12-21
      • 2017-03-04
      相关资源
      最近更新 更多