0
votes

I am trying to move Google Drive file (Google Sheet/Google Document) from Shared Team Drive to another Shared Drive but my Service account is failing to get file filed parents from v3.

I've tested with the Playground and noticed that "parents" field is only returned when you are Authenticated with Google OAuth 2.0 BUT NOT when you are using API Key (or in my case Service auth file).

https://developers.google.com/drive/api/v3/reference/files/get

parents screenshot

no parents screenshot

Working fine with My Drive but not when returning parents for Shared Drive files.

 // My Google Client is initialised
 const googleClient = new google.auth.JWT(
   privatekey.client_email,
   null,
   privatekey.private_key,
   ['https://www.googleapis.com/auth/spreadsheets',
     'https://www.googleapis.com/auth/drive',
     'https://www.googleapis.com/auth/calendar']
 );

 // Google Drive v3
 const googleDrive = google.drive({
   version: 'v3',
   auth: googleClient
 });

 // Getting File details
 const file = googleDrive.files.get({
   fileId,
   fields: '*',
   supportsTeamDrives: true
 });

Can you help me with any ideas or explain me the difference in the API responses?

1

1 Answers

0
votes

API Keys get their permissions based on the project permission (and other settings on the Cloud Console).

OAuth authenticates as the current user and is able to access the APIs as that user would.

You can read more about that here.

In this case, the Try It Feature does not have an API key able to access the methods you are trying to execute.

Hope this helps!