google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

How to set the X-Goog-Drive-Resource-Keys HTTP header while using the googleapis npm package?

Open RakshithNM opened this issue 2 years ago • 4 comments

Got this email about the security update that is going to be enforced on sept 13 2021, and i was trying to figure out how to actually set the X-Goog-Drive-Resource-Keys HTTP header with fileID and resourceKey (the Drive API guide) as its value while listing files in google drive but could not figure out how while using this package. Kindly help.

Thank you.

RakshithNM avatar Aug 11 '21 14:08 RakshithNM

Hi @RakshithNM , have you found the answer? I'm looking for this, too.

pnyennhi avatar Aug 30 '21 10:08 pnyennhi

@pnyennhi not yet, please let me know here if you find the answer

RakshithNM avatar Aug 30 '21 11:08 RakshithNM

Hi @RakshithNM, I think I found the way to set the X-Goog-Drive-Resource-Keys HTTP header for drive API. I'm using create API and setting like this:

var fileMetadata = {
  'name': 'photo.jpg'
};
var media = {
  mimeType: 'image/jpeg',
  body: fs.createReadStream('files/photo.jpg')
};
drive.files.create({
  resource: fileMetadata,
  media: media,
  fields: 'id',
  headers: {
    'X-Goog-Drive-Resource-Keys': 'fileId1/resourceKey1,fileId2/resourceKey2,fileId3/resourceKey3'
  }
}, function (err, file) {
  if (err) {
    // Handle error
    console.error(err);
  } else {
    console.log('File Id: ', file.id);
  }
});

You can try this one and see if it works.

I 'm wondering which API I should include this resourceKey header, such as create, update, delete or more...

pnyennhi avatar Sep 07 '21 03:09 pnyennhi

Hi @RakshithNM , have you found the answer? I'm looking for this, too.

itsjinendrajain avatar Aug 01 '22 07:08 itsjinendrajain