I'm making an script to read data from google spreadsheet using the following script on nodejs:
var url = oauth2Client.generateAuthUrl({
access_type: 'offline',
approval_prompt: 'force',
scope: [
'https://www.googleapis.com/auth/analytics.readonly',
'https://www.googleapis.com/auth/drive',
'https://www.googleapis.com/auth/spreadsheets'
]
});
global.googleapis = { expiry_date: 0 };
google.options({ auth: oauth2Client });
var sheets = google.sheets('v4');
sheets.spreadsheets.get({ spreadsheetId: 'id'}, function(err, data) {
res.send(err, data);
});
But on every get request i'm getting this error:
Request had insufficient authentication scopes.
I checked the Google developers console to enable the Google Drive API and it's enabled, so I dont really know what could it be.
Firstly delete the credentials files ~/.credentials/sheets.googleapis.com-nodejs-quickstart.json
(depending on your setting)
Change the scope variable used for reading cells from Google Spreadsheets from
var SCOPES = ['https://www.googleapis.com/auth/spreadsheets.readonly'];
to
var SCOPES = ['https://www.googleapis.com/auth/spreadsheets'];