Google has build v4 of the Google Sheets API but the documentation of this is still at v3. There are no full examples of how to implement a simple OAuth authentication with Google Sheets API v4.
I see a migration guide here and I also see a partial example here But a full example is nowhere to be found. The "current" version is here and it was last updated in October 2018 without providing a v4 example.
Let's say that after I authorize the user, I'm trying to read a particular spreadsheet in workbook2 and I'm explicitly specifying what columns I need. Then I present that information with Google Visualization API.
So, here's how I do it in Google Sheets v3 legacy.
function makeApiCall() {
var queryString = encodeURIComponent('SELECT A,B,C,E,H');
var tqURL = new google.visualization.Query(
'https://docs.google.com/spreadsheets/d/*yourspreadsheetid*/gviz/tq?gid=*yourworkbookid*&headers=1&tqx=responseHandler:handleTqResponse' + '&access_token=' + encodeURIComponent(gapi.auth.getToken().access_token));
tqURL.send(handleTqResponse);
}
function handleTqResponse(resp) {
var dataTable = resp.getDataTable();
}
For v4, if I follow this partial example here, how do I convert the tqURL to a GET method? and how can I still get the response (rsp) as a DataTable()?
function makeApiCall() {
var params = {
spreadsheetId: 'my-spreadsheet-id', // all clear here
//what about workbook gid?
// The ranges to retrieve from the spreadsheet.
ranges: [], // [A:A,B:B,C:C,E:E,H:H) ????
includeGridData: false,
//no need to include the access_token here?
};
var request = gapi.client.sheets.spreadsheets.get(params);
request.then(function(response) {
console.log(response.result);
//var dataTable = responce.getDataTable(); ??
}, function(reason) {
console.error('error: ' + reason.result.error.message);
});
}