当我尝试使用Windows移动设备(Lumia 800)中的Facebook登录时,我收到错误“不支持的浏览器:IE”。有什么方法可以修复或Facebook必须在他们的脚本中修复。或者可以针对此问题执行任何其他解决方法?请建议。
答案 0 :(得分:0)
我也遇到过这个问题以及我为微软做的一个大项目。我需要在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。如果用户没有登录,则不会有访问令牌。如果用户这样做,则会在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,访问令牌和响应类型的相同(或其他)网址:
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查询中没有访问令牌,请使用服务器端服务(我们将在下面构建)来验证令牌
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)生成应用令牌: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
中检查令牌参数$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 =&#34; https://graph.facebook.com/debug_token?input_token= $ user_access_token&amp; access_token = $ app_token&#34;;
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);
八达-BIM-八达-臂架
我撒了谎,这不是一个快速的解释......但我希望它可以节省你一些时间! Tomer Almog