如何使用重定向帆布授权的Facebook应用程序? [英] How to authorize Facebook app using redirect in canvas?

查看:223
本文介绍了如何使用重定向帆布授权的Facebook应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图进入使得Facebook应用程序,但我遇到了麻烦授权在画布里面一个重定向方案工作。

I'm trying to get into making Facebook apps but I'm having trouble getting authorization working in a redirect scheme inside the canvas.

使用JavaScript API,我得到了它在弹出方案轻松的工作pretty:

Using the javascript api, I got it working pretty easily in a popup scheme:

$("#loginButton").click(function(e) {
    FB.login(function(response) {
        if (response.perms) {
            perms();
        }
}, {perms : 'publish_stream'});

不过,在弹出的应该是一个不必要的额外的点击,因为每一个其它应用我看甚至呈现你的登陆页面之前请求授权。像这样的:

But the popup should be an unnecessary extra click, because every other application I see requests the authorization before even showing you the landing page. Like this:

http://i.imgur.com/yBGzL.png

我的身影,他们只是使用重定向方案。所以,我整天都在尝试不同的方法我可以找到:

I figure they're simply using a redirect scheme. So I spent the entire day trying the different ways I could find:

header("Location: https://graph.facebook.com/oauth/authorize?client_id=" . $gAppId . "&redirect_uri=" . urlencode($gUrl) . "&perms=publish_stream");

header("Location: http://www.facebook.com/login.php?v=1.0&api_key=" . $gApiKey . "&next=" . urlencode($gUrl) . "&canvas=");

header("Location: http://www.facebook.com/connect/uiserver.php?app_id=" . $gAppId . "&next=" . urlencode($gUrl) . "&return_session=0&fbconnect=0&canvas=1&legacy_return=1&method=permissions.request");

但所有的人,而不是显示的授权请求的东西,表明这样一个链接:

But all of them, instead of showing the authorization request stuff, show a link like this:

http://i.imgur.com/bLwPQ.png

欢快的,如果我在新标签中打开的iframe的地址,我得到的授权请求像我想要的。但我想它立即显示,不需要额外的点击,像所有其他应用程序。

Hilariously, if I open the iframe's address in a new tab, I get the authorization request like I wanted. But I want it to display immediately, without an extra click, like every other app.

下面是一个应用程序,是做授权,要求所有在一气呵成的权限,以重定向形式的例子,甚至显示登陆页面之前:

Here's an example of an app that is doing authorization and requesting permissions all in one go, in redirect form, before even displaying the landing page:

www.facebook.com/send.fortune.cookies

www.facebook.com/send.fortune.cookies

他们是如何做的?

推荐答案

我知道这是个月大,现在......但是这是你应该做的添加权限检查到你的画布。

I know that this is months old now... but this is what you should do to add permission checking to your canvas.

if ($session) {
  try {
    $uid = $facebook->getUser();
    $me = $facebook->api('/me');
    $accesstoken=$session['access_token'];
  } catch (FacebookApiException $e) {
    error_log($e);
  }
} 

if($me)
{
   // do what you have to do
}else {
    $loginUrl = $facebook->getLoginUrl(
        array(
            'canvas' => 1,
            'fbconnect' => 0,
            'req_perms' => 'publish_stream'
        )
    );
    echo '<script>top.location="'.$loginUrl.'";</script>';
    //echo '<fb:redirect url="' . $loginUrl . '" />';
   //header('Location: '.$loginUrl);
}

这篇关于如何使用重定向帆布授权的Facebook应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆