gpt4 book ai didi

Facebook JS 连接不支持的浏览器 IE 手机

转载 作者:行者123 更新时间:2023-12-02 03:58:09 25 4
gpt4 key购买 nike

当我尝试在 Windows 移动设备 (Lumia 800) 中使用 facebook 登录时,出现错误“不支持的浏览器:IE”。有什么办法可以修复它,或者 Facebook 必须在他们的脚本中进行修复。或者还有其他解决方法可以解决这个问题吗?请提出建议。

最佳答案

我在为 Microsoft 做的一个大项目中也遇到过这个问题。我需要在 Windows 移动设备上与 Facebook 宣誓,并遇到了同样的错误。这就是我解决它的方法:一般来说,有两种使用 javascript 宣誓的方法 - 这里描述的简单方法(产生此错误): https://developers.facebook.com/docs/javascript/quickstart

以及此处描述的手动构建登录流程: https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow

以下是对第二个选项必须执行的操作的快速说明:

1)异步加载SDK

(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));

2) 在页面加载时检查 access_token。如果用户未登录,则不会有访问 token 。如果用户这样做,则会将访问 token 作为查询附加到 URL,但使用“#”而不是“?”我使用了这个功能:

function getUrlVars()
{
var query = '#';//normally ?
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf(query) + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}

现在确定您是否获得了 access_token:

var urlString = getUrlVars();
var hasAccess=false;
var userToken;
if(typeof(urlString)!='undefined' && typeof(urlString.access_token)!='undefined'){
hasAccess=true;
userToken=urlString.access_token;
}

如果用户具有访问权限,则将其重定向到带有应用 ID、访问 token 和响应类型的相同(或其他)URL:

var appID = 'your app id';
if(!hasAccess){
$('#login').on('click',function(){
var login_redirect_uri = 'http://www.yourpage.com/';
var login_response_type = 'token';
var loginURL = 'https://www.facebook.com/dialog/oauth?client_id='+appID+'&redirect_uri='+login_redirect_uri+'&response_type='+login_response_type;
window.location.replace(loginURL);

});//login-click
}

3) 如果 url 查询中没有访问 token ,请使用服务器端服务(我们将在下面构建)来验证 token

var tokenValidate = 'https://titan-img-gen.aws.af.cm/toeknValidate.php';
$.ajax({
type: 'GET',
url: tokenValidate,
crossDomain: true,
data:{
token:userToken
},
dataType:'json',
success: function(validateData){
if(validateData.error){
showError();
}else{
username = validateData.username;
firstname = validateData.firstname;
lastname = validateData.lastname
//continue your code
}
},
error: function (responseData, textStatus, errorThrown) {
showError();
}
});

4) 服务器端服务(PHP) a) 生成应用 token :https://developers.facebook.com/docs/facebook-login/access-tokens/ b)可能需要同源解析:

header('Access-Control-Allow-Origin: '.$_SERVER['HTTP_ORIGIN']);
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
header('Access-Control-Max-Age: 1000');
header('Access-Control-Allow-Headers: Content-Type, Authorization, X-Requested-With');

c) 定义app_token:

$app_token='*******';

d) 检查 get 中的 token 参数

$reponse = array();
if(!isset($_GET['token']) || $_GET['token']==NULL ){
$reponse['error'] = true;
}else{
$user_access_token = $_GET['token'];
//continue here...
}

e) use facebook graph service to debug token

$fbDebug = "https://graph.facebook.com/debug_token?input_token= $user_access_token&access_token=$app_token";

f)get the json file, decode it and get the user_id from it. you can then retrieve more info from Facebook easily 

try{
$fbResult = file_get_contents($fbDebug);
$fbResultDecode = json_decode($fbResult);
if(isset($fbResultDecode->data->error)){
$reponse['error'] = true;
}else{
$user_id= $fbResultDecode->data->user_id;
$userJSON = file_get_contents("https://graph.facebook.com/$user_id");
$userInfo = json_decode($userJSON);

$reponse['username'] = $userInfo->username;
$reponse['firstname'] = $userInfo->first_name;
$reponse['lastname'] = $userInfo->last_name;

}
}catch(Exception $e){
$reponse['error'] = true;
}

g)return the JSON
header('Content-Type: application/json');
echo json_encode($reponse);

巴达-比姆-巴达-繁荣

我撒谎了,这不是一个快速的解释......但我希望它能节省你一些时间!托默·阿尔莫格

关于Facebook JS 连接不支持的浏览器 IE 手机,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19090591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com