Bry*_*yan 4 javascript facebook ruby-on-rails
我正在使用Facebook JavaScript SDK来实现我网站的登录.我已经在Safari和Firefox上使用它,但在Chrome中却没有.
在调用FB.login方法之后,我能够从Facebook检索访问令牌,但它没有像在Firefox和Safari中那样在cookie中设置访问令牌和用户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'});
});
});
Run Code Online (Sandbox Code Playgroud)
Gra*_*wan 19
如果您在本地测试应用程序,请注意Google Chrome 不支持本地文件(包括localhost)的Cookie,除非您使用该--enable-file-cookies标志启动它.但是,如果您使用本地IP地址,Chrome会支持Cookie 127.0.0.1,以进行测试.
您可以在此处查看有关此行为的讨论:http://code.google.com/p/chromium/issues/detail?id = 535
(答案修改自为什么Chrome会忽略本地jQuery Cookie?)
| 归档时间: |
|
| 查看次数: |
4416 次 |
| 最近记录: |