FB.login与PHP API [英] FB.login with PHP API

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

问题描述

我已经设置了一个Canvas页面,这是一个点击表单提交按钮的FB.login。在以下请求期间,它尝试通过$ facebook-> api('/ me')(Github的最后一个API版本)访问用户数据。它适用于Firefox和Chrome,但不适用于Safari和IE,其中API出现请求验证令牌。有没有人有这个问题或有什么可能造成的?



BR Philipp



编辑: / p>

我在表单提交按钮的点击事件中调用FB.login:

  $('。form-submit',this).click(function(){
FB.getLoginStatus(function(response){
if(response.session){
form .submit();
} else {
FB.login(function(response){
if(response.session&&(permissions ==''|| response.perms) ){
form.submit();
}
else {
}
},{perms:permissions});
}
});
return false;
});

在服务器端,简单地构造php-api对象并尝试获取用户数据:

  $ facebook = new Facebook(array(
'appId'=> $ appid,
'secret'= > $ appsecret,
'cookie'=> TRUE,
));
if($ facebook){
try {
$ me = $ api-> api('/ me');
}
catch(异常$ exc){
//由于无效的授权令牌,在Safari和IE中失败
}
}

signed_request在隐藏的表单元素中传递。

解决方案

我遇到了很多麻烦的JS FB登录的东西。我建议使用更简单的重定向登录使用oauth和从$ php fb api的 getLoginUrl 函数。



所以基本上你做它来自PHP,您检查是否有您的会话,如果您不使用getLoginUrl并重定向到该页面,那么您的使用将被重定向到您的应用程序/网站与有效的会话(如果他接受)。



这是否有帮助?我真的失去了HOURS试图使FB JS登录在任何浏览器上工作,我不能,我已经从那以后切换到所有应用程序中的简单重定向登录方法,并且已经取得圆满成功。


I've set up a Canvas Page which doe's a FB.login on click of a form submit button. During the following request it tries to access the users data via $facebook->api('/me') (last API version from Github). It works in Firefox and Chrome, but not in Safari and IE, where the API fails with "auth token required". Has anybody already had this problem or got an idea what could cause it?

BR Philipp

edit:

I call FB.login inside the click event of a form submit button:

$('.form-submit', this).click(function() {
  FB.getLoginStatus(function(response) {
    if (response.session) {
      form.submit();
    } else {
      FB.login(function(response) {
        if(response.session && (permissions == '' || response.perms)) {
          form.submit();
        }
        else {
        }
      },{perms:permissions});
    }
  });
  return false;
});

On server side in simply construct the php-api object and try to get user data:

$facebook = new Facebook(array(
  'appId' => $appid,
  'secret' => $appsecret,
  'cookie' => TRUE,
));
if ($facebook) {
  try {
    $me = $api->api('/me');
  }
  catch (Exception $exc) {
    // Failure in Safari and IE due to invalid auth token
  }
}

The signed_request is passed inside a hidden form element.

解决方案

I had a lot of troubles with the JS FB login stuff. I recommend using the simpler redirect login using oauth and the getLoginUrl function from php fb api.

So basically you do it from PHP, you check if you have your session, if not you use getLoginUrl and redirect to that page, your use will be then redirected to your app/site with a valid session (if he accepts).

Does this help ? I really lost HOURS trying to make the FB JS login work on any browser and I couldn't, I've switched since then to the simple redirect login method in all of my apps with complete success.

这篇关于FB.login与PHP API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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