Facebook认证问题 [英] Facebook authentication issue

查看:109
本文介绍了Facebook认证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Facebook平台不断变化,结构脆弱,缺乏体面和最新的文档,我感到很生气。



目前,我从FBML迁移应用程序,现在已经不再使用iFrame应用程序,并且有问题的验证。目前,我有一个全局启动脚本,它被加载到每个页面视图中,其中包含以下与身份验证有关的脚本:

  //尝试对Facebook平台进行身份验证
需要dirname(__ FILE__)。 /facebook.php;

$ facebook = new Facebook(array(
'appId'=> APP_ID,
'secret'=> SECRET,
'cookie'=> true
));

$ session = $ facebook-> getSession();

$ user = null;
if($ session){
try {
$ uid = $ facebook-> getUser();
$ user = $ facebook-> api('/ me');
}
catch(FacebookApiException $ e){
error_log($ e);
}
}

如果(!$ user){
$ loginUrl = $ facebook-> getLoginUrl(array(
'req_perms'=> ;'email,user_likes',
'next'=> CANVAS_URL。'/'
));
echo'< script> top.location.href ='。$ loginUrl。';< / script>';
退出;
}

这是根据官方 Facebook PHP SDK 和开发人员的文档,但是当第一次加载应用程序时,只是在一个令人讨厌的重定向圈中出现,我没有想要从哪里开始调试,因为我没有什么可以从Facebook引用。



有没有人有一个验证Facebook iFrame应用程序的工作示例,或者可以看到固有的东西



提前感谢



编辑: strong>忘了提到它在上面的代码的重定向循环中,但是如果我从 $ facebook-> getLoginUrl()调用中删除参数数组,那么最终打破了循环,并从Facebook本身,而不是去我的画布网站在Facebook的iFrame容器之外。例如,URL变为 http://www.woohoobingo.com/facebookv2/?session= {...} 而不是 http:/ /apps.facebook.com/woohoobingo /

解决方案

此行适用于我

  header('P3P:CP =IDC DSP COR CURA ADMa OUR IND PHY ONL COM STA); 

但是正如你所说,它不适用于safari,因为它不会修补它来存储cookies,那么你可以使用另一个
关闭Cookie

  $ facebook = new Facebook(array(
'appId '=> APP_ID,
'secret'=> SECRET,
'cookie'=> false
));

,并尝试使用身份验证后的访问令牌@access_token是传递到您的画布的oauth access_token初始POST请求中的页面。

  $ facebook-> api('/ me?access_token ='。$ access_token) 

希望它有效


I'm getting a bit pissed off with Facebook's platform constantly changing, fragile structure, and lack of decent and up-to-date documentation.

Currently, I'm migrating an app from FBML now that it's deprecated to an iFrame app, and having issues authenticating. Currently, I have a global bootstrap script that is loaded upon each page view that contains the following pertaining to authentication:

// attempt to authenticate against Facebook platform
require dirname(__FILE__) . '/facebook.php';

$facebook = new Facebook(array(
    'appId'  => APP_ID,
    'secret' => SECRET,
    'cookie' => true
));

$session = $facebook->getSession();

$user = null;
if ($session) {
    try {
        $uid = $facebook->getUser();
        $user = $facebook->api('/me');
    }
    catch (FacebookApiException $e) {
        error_log($e);
    }
}

if (!$user) {
    $loginUrl = $facebook->getLoginUrl(array(
        'req_perms' => 'email,user_likes',
        'next' => CANVAS_URL.'/'
    ));
    echo '<script>top.location.href="'.$loginUrl.'";</script>';
    exit;
}

This was put together based on examples in the official Facebook PHP SDK and developer's documentation, but when first loading the app is just goes around in a nasty redirect circle and I have no idea where to start debugging as I've nothing to refer to from Facebook.

Has any one got a working sample of authenticating a Facebook iFrame app, or can see something inherently wrong with the code snippet I have above?

Thanks in advance.

EDIT: Forgot to mention that it goes in a redirect loop with the above code, but if I remove the parameters array from $facebook->getLoginUrl() call then it eventually breaks out of the loop and out of Facebook itself, instead going to my canvas URL outside of Facebook's iFrame container. For example, the URL becomes http://www.woohoobingo.com/facebookv2/?session={...} instead of http://apps.facebook.com/woohoobingo/.

解决方案

This line works for me

header('P3P: CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA"');

But as you said it is not working in safari because it do not patch it to store cookies then you can use an alternative That turn off cookies

$facebook = new Facebook(array(
    'appId'  => APP_ID,
    'secret' => SECRET,
    'cookie' => false
));

and try to use the access token after authentication @access_token is the oauth access_token that gets passed to your canvas page in the initial POST request.

$facebook->api('/me?access_token='.$access_token);

Hope it works

这篇关于Facebook认证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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