Javascript 如何针对Google Api撤销身份验证令牌客户端
我正在尝试使用GoogleAPI客户端代码撤销令牌 我的代码如下所示:Javascript 如何针对Google Api撤销身份验证令牌客户端,javascript,jquery,oauth,google-api,google-analytics-api,Javascript,Jquery,Oauth,Google Api,Google Analytics Api,我正在尝试使用GoogleAPI客户端代码撤销令牌 我的代码如下所示: $.get("https://accounts.google.com/o/oauth2/revoke?token=" + accessToken, function () { window.location.reload(); }); 我得到了以下错误 无法加载XMLHttpRequest 起源 访问控制允许原点不允许 @krg评论如下: 基于此错误,您似乎无法在此客户端上执行此操作。也许您需要一
$.get("https://accounts.google.com/o/oauth2/revoke?token=" + accessToken, function () {
window.location.reload();
});
我得到了以下错误
无法加载XMLHttpRequest
起源
访问控制允许原点不允许
@krg评论如下:
基于此错误,您似乎无法在此客户端上执行此操作。也许您需要一个服务器端脚本来处理域内的请求。您还可以探索解决方案。下面是一个使用该解决方案的示例 我使用相同的代码在服务器端完成了此操作:
$.ajax({
url:“https://accounts.google.com/o/oauth2/revoke?token=10100101",
数据类型:'jsonp',//注意!jsonp经过一些研究,我发现您可以通过在jquery ajax请求中指定一个数据类型:'jsonp'选项来绕过cors限制。相关信息如下:
现在jsonp不起作用了。他们已经将内容类型更改为“application/x-www-form-urlencoded”
基于此错误,您似乎无法在此客户端上执行此操作。也许您需要一个服务器端脚本来处理域内的请求。您也可以探索解决方案。下面是使用此解决方案的示例。这非常有效,但有没有办法在没有jquery的情况下执行此操作?
$.ajax({
url:"https://accounts.google.com/o/oauth2/revoke?token=10100101",
dataType: 'jsonp', // Notice! JSONP <-- P (lowercase)
success:function(json){
console.log(arguments);
// do stuff with json (in this case an array)
alert("Success");
},
error:function(){
alert("Error");
},
});
$.ajax({
type: 'GET',
url: revokeUrl,
async: false,
contentType: "application/json",
dataType: 'jsonp',
success: function(nullResponse) {
// Do something now that user is disconnected
// The response is always undefined.
},
error: function(e) {
// Handle the error
// console.log(e);
// You could point users to manually disconnect if unsuccessful
// https://plus.google.com/apps
}
});
$.ajax({
type: 'GET',
url: "https://accounts.google.com/o/oauth2/revoke?token=dsfgdfsg.98sdfgsdfg9sd8fgsdfgs.sdfg89dsfg",
async: false,
contentType: "application/x-www-form-urlencoded",
success: function(nullResponse) {
// Do something now that user is disconnected
// The response is always undefined.
},
error: function(e) {
console.log(e)
}
});