我使用Facebook的JavaScript SDK来实现我的网站登录后不设置访问令牌的cookie中的铬。我已经在Safari和Firefox上使用它,但在Chrome中却没有。Facebook上的JavaScript SDK的FB.login呼叫
中的FB.login方法被调用后,我能够检索从Facebook访问令牌,但像它在Firefox和Safari浏览器也它不是在饼干设置的访问令牌和用户ID。目前,我手动将访问令牌和用户ID写入cookie以便登录流程正常工作,但仍然让我感到困惑,即访问令牌不是单独在Chrome中编写的。
有没有人碰到这个之前来了解在手的位置吗?非常感激。
下面是我的init和登录逻辑代码:
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'});
});
});