这是我在这个网址上发帖子时收到的数据:
POST https://accounts.google.com/o/oauth2/token 400(错误请求)
对象{错误:“invalid_request”,error_description:“参数不是 允许使用此消息类型:session_state“}
我不知道问题可能是什么。此代码将在离子应用程序中调用。
$scope.gpluslogin = function() {
var ref = window.open('https://accounts.google.com/o/oauth2/auth?client_id=' + clientId + '&redirect_uri=http://localhost/callback&scope=https://www.googleapis.com/auth/plus.login%20https://www.googleapis.com/auth/plus.me&approval_prompt=auto&response_type=code&access_type=offline&include_granted_scopes=false', '_blank', 'location=no');
//var ref = window.open('https://accounts.google.com/o/oauth2/auth?client_id=' + clientId + '&redirect_uri=http://localhost/callback&scope=https://www.googleapis.com/auth/plus.login%20https://www.googleapis.com/auth/plus.me&approval_prompt=force&response_type=code', '_blank', 'location=no');
ref.addEventListener('loadstart', function(event) {
if((event.url).startsWith("http://localhost/callback")) {
requestToken = (event.url).split("code=")[1];
$http({method: "post", url: "https://accounts.google.com/o/oauth2/token", data: "client_id=" + clientId + "&client_secret=" + clientSecret + "&redirect_uri=http://localhost/callback" + "&grant_type=authorization_code" + "&code=" + requestToken })
.success(function(data) {
accessToken = data.access_token;
console.log(data);
console.log(accessToken);
$.ajax({
url: "http://192.168.137.118:3000/api/v1/save_gp_auth",
data: {'gp_auth_token':accessToken,'user_id':$rootScope.currentuser_id},
dataType: "json",
type: "post",
success: function(data){
if(data.gp_status=="gp_saved" || data.gp_status=="gp_updated")
{ $rootScope.gp_toggle=true;
if($rootScope.fb_toggle==true && $rootScope.gp_toggle==true)
$scope.toggle_status="both_connected";
else
$scope.toggle_status="gp_connected";
}
}
});
})
.error(function(data, status) {
console.log(data);
});
ref.close();
}
});
}
然而,当我将范围更改为“电子邮件”之类的内容时,它会起作用,并为我提供访问令牌。
答案 0 :(得分:0)
鉴于它适用于email
范围,我猜这是与其他范围的URI编码问题。
使用encodeURIComponent
尝试URI编码范围,即:
encodeURIComponent("https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me")
哪些输出:https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.login%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fplus.me