2011-02-28 102 views
0

嗨我最近修改我的应用程序首先它只需要基本信息。来自用户的许可,但现在我也想流发布权限。所以,我在我的索引页上的检查,如果不向用户授予流出版许可,我只是给他的权限如下对话框:在FB.ui中使用方法permissions.request重定向uri无法正常工作

<?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>"; 
    } 
?> 

这段代码显示许可箱正常,但问题是,当用户同意,他被重定向到我画布网址(服务器页面上的网址),而不是画布页面(即http://apps.facebook.com/xyz)。为了解决这个问题,我添加了redirect_uri作为

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

但它仍然不起作用。

请帮我解决这个问题。

回答

4

试试这个:

<?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


UPDATE:
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"))); 
}