Abbiamo un'applicazione che si basa su Google per autenticare i suoi utenti contro il nostro account Google Apps e quindi effettuare alcune verifiche server e ricerche di gruppo.L'API di Google+ non restituisce access_token Javascript
Recentemente google ha cambiato il nome dell'oggetto che conteneva la variabile access_token che abbiamo bisogno di autenticare. Nei documenti (https://developers.google.com/identity/sign-in/web/reference#googleusergetbasicprofile) si dice che access_token è disponibile dal metodo getAuthResponse(), tuttavia quando lo uso viene restituito come non definito. Ispezionando l'oggetto dopo console.log() vengono visualizzati tutti gli altri campi menzionati, ad eccezione di access_token. Sono preoccupato che Google cambierà nuovamente l'oggetto in futuro e ci lascerà senza la nostra applicazione. Ecco il codice.
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
<script src="https://apis.google.com/js/platform.js" async defer></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<meta name="google-signin-client_id" content="XXX.apps.googleusercontent.com">
<script>
//This happens after the user has authenticated with Google and has been passed
//back to the page
function onSignIn(googleUser) {
//Check to see whether the user is trying to sign out.
if (window.location.href.indexOf("signOut=1") !== -1) {
//Sign them out of the application.
signOut();
//redirect them to the same page, without the signOut query string so they can log back in if want
window.location.href='googlesigninform.html'
return false;
}
//Grab the token, access token and email.
var _id = googleUser.getAuthResponse().id_token; //This works
var _accessToken = googleUser.Ka.access_token; //This works but changed from googleUser.B.access_token
var profile = googleUser.getBasicProfile(); //Works
console.log(googleUser.access_token); //Undefined
console.log(googleUser.getAuthResponse().access_token);//Undefined
//Make a post request to the API
makePostRequest(_id, _accessToken, profile.getEmail());
}
Qual è il modo corretto di accedere alla variabile access_token?
E 'questo quello stupido di una domanda che nessuno risposte? –
È successo di nuovo ieri sera. L'oggetto grezzo ancora una volta ha cambiato nome e ha rotto le nostre applicazioni. –