我不确定如何使用承诺等待谷歌返回id_token。然后我会使用该令牌发出ajax请求。目前,它只是在拥有令牌之前立即执行ajax请求。
<script>
function onSignIn(googleUser) {
id_token = googleUser.getAuthResponse().id_token;
}
var app = angular.module('myApp', ['ngDialog']);
app.controller('directory_controller', function($scope, $q, $http, ngDialog) {
$http({
headers: { "Content-Type": "application/x-www-form-urlencoded" },
url: "my_ajax.php",
method: "POST",
data: "gtoken=" + id_token
})
.then(function successCallback(response) {
console.log("success");
console.log(response);
}),
function(response) {
console.log("failure");
console.log(response);
}
});
</script>
<div ng-app='myApp'>
<div ng-controller='directory_controller'>
</div>
</div>
<div class="g-signin2" data-onsuccess="onSignIn" data-theme="dark"></div>