如何撤消针对Google Api的身份validation令牌客户端

我正在尝试使用Google Api客户端代码撤消令牌。

我的代码看起来像这样:

$.get("https://accounts.google.com/o/oauth2/revoke?token=" + accessToken, function () { window.location.reload(); }); 

我收到以下错误?

XMLHttpRequest无法加载https://accounts.google.com/o/oauth2/revoke?token=tokenishere来自Access-Control-Allow-Origin不允许来源http://balblabla.com 。

经过一些研究后,我发现你可以通过在jquery ajax请求中指定一个dataType:’jsonp’选项来绕过cors限制。 相关信息位于: https : //developers.google.com/+/web/signin/disconnect

 $.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 } }); 

继@ krg的评论之后:

根据错误,您似乎无法在此客户端上执行此操作。 也许您需要一个服务器端脚本来处理域内的请求。 您也可以探索此解决方案。 这是使用该解决方案的jsFiddle示例。

我在服务器端使用相同的代码完成了这个:

 $.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"); }, }); 

哪个有效。