bim2016
bim2016

Reputation: 105

Get driveId of my personal google drive (My Drive)

I have a NodeJS app to read files in my google drive, source code like below:

  var d = google.drive({ version: "v2", auth: oauth2Client });
  var drive = d.drives.get({ driveId: "my-drive" });

need to have driveId as one of parameters, how to get it? besides, it's not shared drive, just my personal drive, I used drive name (my-drive) which is obvious wrong, URL and error message as below:

url: 'https://www.googleapis.com/drive/v2/drives/my-drive',

GaxiosError: Shared drive not found: my-drive

Upvotes: 0

Views: 2588

Answers (2)

Gabriel Carballo
Gabriel Carballo

Reputation: 1343

Checking that you are trying to call your "My Drive" id however there is no API call to retrieve this information as it's not a folder per se, instead you can as well call the parent folders that are saved in your personal Drive, you can use a List that will return the parent folder ID about the file ID you are trying to work on.

The Drive.get method you are referring to only works for shared drive only as noted in the documentation:

Gets a shared drive's metadata by ID.

In this case you won't be able to use this API call if you are not trying to retrieve data from a Shared Drive itself.

Upvotes: 1

Tanaike
Tanaike

Reputation: 201603

I believe your goal is as follows.

  • You want to retrieve the folder ID of the root folder of your Google Drive using googleapis for Node.js.

In this case, I thought that the method of "Files: get" can be used. When this is reflected in your script, it becomes as follows.

Modified script:

var d = google.drive({ version: "v2", auth: oauth2Client });
var drive = await d.files.get({ fileId: "root" });
var id = drive.data.id;
console.log(id);

Note:

  • In the case of var drive = d.drives.get({ driveId: "my-drive" });, drive is Promise. Please be careful this.

Reference:

Upvotes: 4

Related Questions