Dan*_*ler 30 javascript iphone facebook ios
Facebook OAuth弹出窗口仅在iOS上的Chrome中引发错误.developers.facebook.com和谷歌都没有透露任何相关信息.想法?
Kim*_* D. 16
对于这种情况,您可以使用重定向方法(通过检测用户代理是chrome ios):
https://www.facebook.com/dialog/oauth?client_id={app-id}&redirect_uri={redirect-uri}
Run Code Online (Sandbox Code Playgroud)
点击此处查看更多信息https://developers.facebook.com/docs/facebook-login/login-flow-for-web-no-jssdk/
备注:在这种情况下,我个人使用服务器OAuth,但这应该可以解决问题并且非常简单
vsy*_*ync 11
这就是我做的方式(专门修复iOS chrome)
// fix iOS Chrome
if( navigator.userAgent.match('CriOS') )
window.open('https://www.facebook.com/dialog/oauth?client_id='+appID+'&redirect_uri='+ document.location.href +'&scope=email,public_profile', '', null);
else
FB.login(null, {scope: 'email,public_profile'});
Run Code Online (Sandbox Code Playgroud)
以下是针对Chrome iOS问题的FB JS Auth 的完整解决方法http://seanshadmand.com/2015/03/06/facebook-js-login-on-chrome-ios-workaround/
JS用于检查身份验证,手动打开FB身份验证页面并在完成后刷新原始页面上的身份验证令牌:
function openFBLoginDialogManually(){
// Open your auth window containing FB auth page
// with forward URL to your Opened Window handler page (below)
var redirect_uri = "&redirect_uri=" + ABSOLUTE_URI + "fbjscomplete";
var scope = "&scope=public_profile,email,user_friends";
var url = "https://www.facebook.com/dialog/oauth?client_id=" + FB_ID + redirect_uri + scope;
// notice the lack of other param in window.open
// for some reason the opener is set to null
// and the opened window can NOT reference it
// if params are passed. #Chrome iOS Bug
window.open(url);
}
function fbCompleteLogin(){
FB.getLoginStatus(function(response) {
// Calling this with the extra setting "true" forces
// a non-cached request and updates the FB cache.
// Since the auth login elsewhere validated the user
// this update will now asyncronously mark the user as authed
}, true);
}
function requireLogin(callback){
FB.getLoginStatus(function(response) {
if (response.status != "connected"){
showLogin();
}else{
checkAuth(response.authResponse.accessToken, response.authResponse.userID, function(success){
// Check FB tokens against your API to make sure user is valid
});
}
});
}
Run Code Online (Sandbox Code Playgroud)
和FB auth转发到并调用刷新主页的Opener Handler.请注意,Chrome iOS中的window.open也存在错误,因此如上所述正确调用它:
<html>
<head>
<script type="text/javascript">
function handleAuth(){
// once the window is open
window.opener.fbCompleteLogin();
window.close();
}
</script>
<body onload="handleAuth();">
<p>. . . </p>
</body>
</head>
</html>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
22517 次 |
最近记录: |