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

发布于 2024-10-19 16:20:12 字数 960 浏览 2 评论 0原文

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

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

但它仍然不起作用。

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

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难如初 2024-10-26 16:20:12

请尝试以下操作:

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

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")) );
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文