Facebook登录未在Safari/iPhone中打开
问题描述:
我正在创建一个显示Facebook朋友的应用程序。首先,用户需要点击登录按钮,然后填写登录ID和密码后会出现一个简单的弹出窗口,它会显示好友列表。
一切正常,并在Firefox,Chrome,IE上运行,但它不会在Safari和iPhone中打开弹出窗口。
有人建议我在channelUrl
添加域名和频道名称。我创建了一个channel.html
并添加引用,但它没有帮助我。
我搜索了很多,但没有找到有用的。Facebook登录未在Safari/iPhone中打开
这是我的代码。
Custom.js
function getUser()
{
FB.init({
appId : '289403314507596', // App ID
channelUrl : 'http://bc2-236-161.compute-1.amazonaws.com/html/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
(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));
//check current user login status
FB.getLoginStatus(function(response) {
if (response.status === 'connected') {
window.location="facebook_friend.html"
loadFriends();
} else {
//user is not connected.
FB.login(function(response) {
if (response.authResponse) {
window.location="facebook_friend.html"
loadFriends();
} else {
alert('User cancelled login or did not fully authorize.');
}
});
}
});
}
//start from here
$(document).ready(function(){
$('.load-button').click(function(){
getUser();
});
});
channel.html
<script src="//connect.facebook.net/en_US/all.js"></script>// i add this line in channel.html
refer_friend.html
我在这个文件中添加的custom.js
参考
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<img src="includes/fb-btn1.png" class="load-button" style="
width: 290px;
Height: 40px;
margin-top: 5px;"/>
答
好吧......浪费我满后当天我得到了答案。使用Javascript_Facebook Sdk
,当你点击登录按钮时,它会打开弹出窗口。在Safari或iPhone(我的),我启用阻止弹出选项。
因此我无法看到Facebook登录窗口。你需要允许弹出窗口。
您可以通过点击
Safari-disable Block pop-up windows
或
safari-preference-then disable checkbox of pop-up window's
允许弹出窗口或者您可以使用键盘快捷键:
shift-[command key]-K.
欢呼。
您的代码的主要问题是您自动调用'FB.login' - 然后弹出窗口很可能会被当前浏览器阻止。一般建议是仅在明确的用户交互中调用该方法,例如,点击链接/按钮触发登录。 – CBroe
感谢这些信息。我会试试这个。 –
Safari看起来很敏感。如果您在上面的代码中调用FB.getLoginStatus,则会发生同样的情况。目前在Safari Version 6.0.5(7536.30.1)中遇到了这个问题。我认为它是因为FB.login在一个函数内被调用,即使被用户单击事件触发/调用... – Hans