I am trying to use the (experimental) newBatchRequest method in the NodeJS googleapis library (https://github.com/google/google-api-nodejs-client), but the results returned all return a 401 Invalid Credentials error from Google. The exact same call with the exact same auth client (same credentials) works as expected when sending a single request without using newBatchRequest.
Here's the batch request code:
var c = client.newBatchRequest()
async.each(files, function(fileid, cb) {
c.add(client.drive.files.get({fileId:fileid}));
cb();
},
function(err) {
console.log('client is')
console.log(oauth2Client)
c.withAuthClient(oauth2Client).execute(function(err, results) {
console.log(err)
console.log(results);
})
})
This produces in console.log an array full of the following error:
{ errors: [ [Object] ],
code: 401,
message: 'Invalid Credentials' }
Without using batchRequest and running the exact same call (drive.files.get) with the exact same withAuthClient(oauth2Client), the following code behaves as expected. The following does NOT produce an error. Note that the oauth2Client variable being passed in is exactly the same, and within the same scope.
client.drive.files.get({fileId:fid})
.withAuthClient(oauth2Client)
.execute(function(err, results){
[...etc...]
Any ideas on what could be going on here?
Thanks!