'use strict'; // https://developers.google.com/sheets/api/guides/authorizing // https://www.googleapis.com/auth/spreadsheets.readonly // Scope names // https://developers.google.com/drive/api/v3/about-auth // Google Sheets API // https://developers.google.com/sheets/api/guides/migration#list_spreadsheets_for_the_authenticated_user function onSignIn(googleUser) { var profile = googleUser.getBasicProfile(); var id_token = googleUser.getAuthResponse().id_token; var access_token = googleUser.getAuthResponse(); console.log('ID: ' + profile.getId()); // Do not send to your backend! Use an ID token instead. console.log('Name: ' + profile.getName()); console.log('Image URL: ' + profile.getImageUrl()); console.log('Email: ' + profile.getEmail()); // This is null if the 'email' scope is not present. console.log('access_token', access_token); console.log('id_token', id_token); window .fetch('https://oauth2.googleapis.com/tokeninfo?id_token=' + id_token) .then(function(resp) { return resp.json().then(function(data) { console.log(data); }); }); /* window .fetch( "https://www.googleapis.com/drive/v3/files?q=mimeType%3D'application%2Fvnd.google-apps.spreadsheet'", { headers: {Authorization: 'Bearer ' + access_token.access_token}, }, ) .then(function(resp) { return resp.json().then(function(data) { console.log(data); }); }); window .fetch('https://spreadsheets.google.com/feeds/spreadsheets/private/full', { headers: {Authorization: 'Bearer ' + access_token.access_token}, }) .then(function(resp) { return resp.json().then(function(data) { console.log(data); }); }); */ } function signOut() { var auth2 = gapi.auth2.getAuthInstance(); auth2.signOut().then(function() { console.log('User signed out.'); }); }