Я не смог найти очень много примеров или ответов Как сделать это в HTML и JavaScript, поэтому я приехал сюда за помощью. < /p>
Вот мой код для получения токена: < /p>
Код: Выделить всё
function getToken(){
let credentials;
var data = {'code': authCode,
'client_id': clientid
'client_secret': clientsecret,
'redirect_uri': redirecturi,
'grant_type': 'authorization_code'};
const xhr = new XMLHttpRequest();
xhr.open("POST", "https://oauth2.googleapis.com/token");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200){
credentials = JSON.parse(this.response);
gapi.client.SetToken(credentials.access_token);
}
else {
document.getElementById("error").innerHTML = this.readyState + " + " + this.response;
}
}
xhr.send(data);
}
Это создает выход:
3 + {"error": "unsupported_grant_type", "error_description": "Invalid Grant_type:"} < /p>
< /blockquote>
Может ли кто -нибудь дать мне намек на то, что я мог бы сделать не так? Очень ценится!
Подробнее здесь: https://stackoverflow.com/questions/794 ... type-error