开发者

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

Hi I modify my application recently first it just takes basic info. permission from users but now I want stream publish permission too. So I check on my index page if users not granted stream publish permission I just show him permission dialog box as follows:

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

This code shows permission box properly but problem is that when user grants permission he is redirect to my canvas url (url on servers page) and not on canvas page(i.e. http://apps.facebook.com/xyz). To solve this problem I added redirect_uri to it as

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

but still it's not working.

Please help me how to solve this problem.


Try this instead:

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

You can also use FQL to check for the permission. More about that can be found here.


UPDATE:
Facebook introduced the permissions connection and now it can be used instead of the old 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")) );
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜