FB.login调用后,JavaScript JavaScript SDK不会在chrome中设置访问令牌cookie [英] Facebook JavaScript SDK does not set access token cookie in chrome after FB.login call

查看:111
本文介绍了FB.login调用后,JavaScript JavaScript SDK不会在chrome中设置访问令牌cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Facebook JavaScript SDK来实现我的网站登录。我已经在Safari和Firefox上工作,但不在Chrome中。

调用FB.login方法后,我可以从Facebook中检索访问令牌,但不会在Cookie中设置访问令牌和用户ID,例如它在Firefox和Safari中。目前,我手动将访问令牌和用户ID写入cookies,以便登录流程正常工作,但仍然存在错误,表明访问令牌不是单独使用Chrome编写的。



以前有人遇到过,知道手头的修复吗?非常感谢。



以下是我的初始和登录逻辑的代码:

  window.fbAsyncInit = function(){
FB.init({
appId:#{AppConfig.facebook ['app_id']},// App ID
status: true,//检查登录状态
cookie:true,//启用Cookie以允许服务器访问会话
xfbml:true // parse XFBML
});

//其他初始化代码在这里
};

//异步加载SDK
(function(d){
var js,id ='facebook-jssdk',ref = d.getElementsByTagName('script')[ 0];
if(d.getElementById(id)){return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src =//connect.facebook.net/en_US/all.js;
ref.parentNode.insertBefore(js,ref);
}(document));

$(function(){
$(。fb-login-button)。click(function(){
FB.login(function(response){
if(response.authResponse){
console.log(Welcome!Fetching your information ...);
$ .cookie(user_id,response.authResponse.userID);
$ .cookie(access_token,response.authResponse.accessToken);
window.location =#{oauth_facebook_callback_url};
} else {
console.log取消登录或未完全授权。);
}
},{scope:'publish_stream,offline_access,email,user_events,create_event,user_location'});
});
});


解决方案

如果您在本地测试您的应用程序,请注意除非您使用 - 启用文件启动,否则Google Chrome 不支持本地文件的Cookie(包括 localhost ) -cookies 标志。但是,如果您使用本地IP地址( 127.0.0.1 )进行测试,则Chrome会支持Cookie。



您可以在此处查看有关此行为的讨论: http:// code。 google.com/p/chromium/issues/detail?id=535



(从为什么Chrome忽略本地的jQuery Cookie?


I'm using the Facebook JavaScript SDK to implement login for my site. I've already got it working on Safari and Firefox, but not in Chrome.

After the FB.login method is called, I'm able to retrieve the access token from Facebook, but it's not setting the access token and user ID in the cookies like it does in Firefox and Safari. Currently, I'm manually writing the access token and the user ID to the cookies so the login flow works but it still bugs the heck out of me that the access token is not written in Chrome alone.

Has anybody come across this before and know a fix at hand? Much appreciated.

Below are my code for the init and login logic:

window.fbAsyncInit = function() {
  FB.init({
    appId      : "#{AppConfig.facebook['app_id']}", // App ID
    status     : true, // check login status
    cookie     : true, // enable cookies to allow the server to access the session
    xfbml      : true  // parse XFBML
  });

  // Additional initialization code here
};

// Load the SDK Asynchronously
(function(d){
   var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
   if (d.getElementById(id)) {return;}
   js = d.createElement('script'); js.id = id; js.async = true;
   js.src = "//connect.facebook.net/en_US/all.js";
   ref.parentNode.insertBefore(js, ref);
 }(document));

$(function() {
  $(".fb-login-button").click(function() {
    FB.login(function(response) {
      if (response.authResponse) {
        console.log("Welcome! Fetching your information...");
        $.cookie("user_id", response.authResponse.userID);
        $.cookie("access_token", response.authResponse.accessToken);
        window.location = "#{oauth_facebook_callback_url}";
      } else {
        console.log("User cancelled login or did not fully authorize.");
      }
    }, {scope: 'publish_stream,offline_access,email,user_events,create_event,user_location'});
  });
});

解决方案

If you're testing your application locally, note that Google Chrome does not support cookies for local files (including localhost) unless you start it with the --enable-file-cookies flag. Chrome does, however, support cookies if you use your local IP address—127.0.0.1— for testing.

You can view a discussion on this behavior here: http://code.google.com/p/chromium/issues/detail?id=535

(Answer modified from Why does Chrome ignore local jQuery cookies?)

这篇关于FB.login调用后,JavaScript JavaScript SDK不会在chrome中设置访问令牌cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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