JS SDK FB.login()工作,但弹出对话框在登录后保持打开状态 [英] JS SDK FB.login() works but pop-up dialog is staying open after logged in

查看:190
本文介绍了JS SDK FB.login()工作,但弹出对话框在登录后保持打开状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





通过调用初始化后的问题 FB.Init()异步(因为这全都包裹在一个 window.fbAsyncInit 函数中)登录弹出;我登录,然后弹出窗口刷新显示一个白页,弹出窗口保持打开,不关闭...为什么?我正在等待在 FB.login()回调中检查response.session,但似乎我从来没有收到它,因为这个弹出窗口似乎只是坚持在那里,该进程似乎刚刚停止,您登录后,我只是想到这个弹出窗口将关闭并返回我的回调自动回调。为什么弹出窗口不会消失?



我在登录后复制了弹出窗口的URL,并显示以下URL,因此它看起来像响应是在那里,但是为什么不弹出窗口关闭,所以我的回调可以处理响应?

  http ://static.ak.fbcdn.net/connect/xd_proxy.php# =安培; CB = f18fe0b7c66da54&安培;来源= HTTP%3A%2F%2Flocalhost%2Ff3745f32ed63a7a&安培;关系=开瓶器&安培;运输= PostMessage的&安培;帧= f18adb488566372&安培;结果= user_photos&安培;会话= {%22session_key%22%3A%222.vH4SVCisnh8HJWjEI1Vy_Q __ 3600.1280106000-100001379631246%22%2C%22uid%22%3A%22100001379631246%22%2C%22expires%22%3A1280106000%2C%22secret%22%3A。 %22TH45WFg8I_5r_cOoVIujjg __%22%2C%22access_token%22%3A%22132444323462464 | 2.vH4SVCisnh8HJWjEI1Vy_Q __ 3600.1280106000-100001379631246 |。q123iPQcKY45xWXtOZ2ebOOZTQQ%22%2C%22sig%22%3A%22a75e85af2354292bfdcf90b9d319ebf7%22} 

我注意到当FB.login()被调用时,登录弹出窗口出现,我在FireBug中看到这个错误,谈论如何不喜欢我正在测试本地主机或我猜想的东西:



未捕获的异常:[异常...组件返回的故障代码:0x80004005(NS_ERROR_FAILURE)[nsIDOMLocation.host]nsresult:0x80004005(NS_ERROR_FAILURE)位置:JS frame :: chrome:// smarterwiki / content / smarterwiki。 js :: anonymous :: line 1225data:no]



该错误让我烦恼...我需要弄明白为什么会出现,我敢打赌,不是唯一一个在本地测试时看到这个的人。在Facebook论坛或其他地方,无论何时在网路上排除故障,我都看不到任何信息。我看到别人有这个问题,但没有决议。



所以当你实现你的时候,你的Facebook弹出窗口刚刚关闭用户登录后,还是需要做一些特别的事情来完成这个过程? p>

另外,我注意到如果我手动关闭该弹出窗口,然后去检查该cookie是否生成以包含我的会话,那不是($ code> fbs_ [yourappid] cookie)。所以看起来像是在这里过早地结束了。我有我的初始cookie:真的,所以我不知道这个问题是弹出的对话框是不是关闭是相关的cookie也没有被客户端在我的测试PC上。

解决方案

最近我一直在努力解决这个问题。问题出现在没有哪里,大概来自于Facebook JS SDK的一些变化。对于它的价值,我计划永远不要使用JS SDK,这些随机问题吃了我的时间。



无论如何,这里是我曾经遇到的问题。

  var accessToken,fb_response; 

if(window.location.hash.length< 30){
window.location =http://www.facebook.com/dialog/oauth?client_id=YOUR_ID&redirect_uri = YOUR_URL&安培;范围= YOUR_PERMISSIONS&安培; RESPONSE_TYPE =记号;
} else {
fb_response = window.location.hash;
accessToken = fb_response.substr(14,fb_response.indexOf(& expires) - 14);
FB._authResponse = {
accessToken:accessToken
};
window.location.hash =;
FB.api(/ me,function(profile){
if(profile.id){
app_init();
} else {
alert 连接到Facebook的问题);
}
});
}

基本上我将用户发送到Facebook oauth对话框,当他们返回时我抓住来自哈希的访问令牌。然后我将内部访问令牌参数设置在Facebook对象上。一旦这样做,您可以使所有正常的Facebook Api调用。



希望这有助于某人!
对于未来的项目我一定会坚持服务器端的验证流程,你有更多的控制!


I am using the JS SDK for Facebook based on the NEW GraphAPI for Auth/Login.

Has anyone had this issue when logging in after FB.login() was called via the JS SDK?

The problem: after I initialize by calling FB.Init() asynchronously (because this all wrapped in a window.fbAsyncInit function) the login pops up; I log in but then that pop-up refreshes to show a white page and the pop-up stays open and does not close...why? I am waiting to check response.session in the FB.login() callback but it seems as though I never get it back because this pop-up seems to just stick there and the process appears to just halt after you're logged in and I just figured this pop-up would just close and return me the response.session in the callback automatically. Why would that pop-up not go away?

I copied the url from the pop-up after I'm logged in and showing white the following url so it looks like the response is there but then why isn't that pop-up window closing so my callback can handle the response??

http://static.ak.fbcdn.net/connect/xd_proxy.php#?=&cb=f18fe0b7c66da54&origin=http%3A%2F%2Flocalhost%2Ff3745f32ed63a7a&relation=opener&transport=postmessage&frame=f18adb488566372&result=user_photos&session={%22session_key%22%3A%222.vH4SVCisnh8HJWjEI1Vy_Q__.3600.1280106000-100001379631246%22%2C%22uid%22%3A%22100001379631246%22%2C%22expires%22%3A1280106000%2C%22secret%22%3A%22TH45WFg8I_5r_cOoVIujjg__%22%2C%22access_token%22%3A%22132444323462464|2.vH4SVCisnh8HJWjEI1Vy_Q__.3600.1280106000-100001379631246|q123iPQcKY45xWXtOZ2ebOOZTQQ.%22%2C%22sig%22%3A%22a75e85af2354292bfdcf90b9d319ebf7%22}

I did notice that when FB.login() is called and the login pop-up comes up, I see this error in FireBug talking about how it doesn't like the fact that I'm testing over localhost or something I guess:

uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE) [nsIDOMLocation.host]" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: chrome://smarterwiki/content/smarterwiki.js :: anonymous :: line 1225" data: no]

that error bothers me...I need to figure out why it's coming up and I bet you I'm not the only one who has seen this when testing locally. I see no info though on troubleshooting this on the net anywhere either on the Facebook forums or elsewhere. I see others have had this issue but no resolution.

So when you implemented yours, did your facebook pop-up just close after the user is logged in or did you need to do something special to finish this process?

Also, I notice if I manually close that pop-up then go to check if that cookie was generated to contain my session, it's not (the fbs_[yourappid] cookie). So it looks like something ends prematurely here. I've got in my init cookie: true so I wonder if this problem were the pop-up dialog is not closing is related to the cookie also not being created client-side on my test PC.

解决方案

I struggled with this issue recently. The problem appeared from no where, presumably from some change in the Facebook JS SDK. For what its worth I plan to never use the JS SDK again, these random issues eat up my time.

Anyway here is the hack that I used to get around the issue.

var accessToken, fb_response;

if (window.location.hash.length < 30) {
  window.location = "http://www.facebook.com/dialog/oauth?client_id=YOUR_ID&redirect_uri=YOUR_URL&scope=YOUR_PERMISSIONS&response_type=token";
} else {
  fb_response = window.location.hash;
  accessToken = fb_response.substr(14, fb_response.indexOf("&expires") - 14);
  FB._authResponse = {
    accessToken: accessToken
  };
  window.location.hash = "";
  FB.api("/me", function(profile) {
    if (profile.id) {
       app_init();
    } else {
       alert("Problem connecting to Facebook");
    }
  }); 
}

Basically I send the user to the Facebook oauth dialog and when they return I grab the access token from the hash. I then set the internal access token parameter on the Facebook Object. Once this is done you can make all the normal Facebook Api calls.

Hopefully this helps someone! For future projects I will definitely stick to a server side auth flow, you have a lot more control!

这篇关于JS SDK FB.login()工作,但弹出对话框在登录后保持打开状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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