google-drive-api

How to receive FileID in Google Drive by API


I can see my public shared drive in link https://drive.google.com/drive/folders/1MXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX?usp=sharing but I want to know FileID for each file for using this Google interface https://drive.google.com/uc?id=1WCvnW61uyPenkKNWTrK9WA6X5ZFTSeje What API I need to using? I try to use this API https://developers.google.com/drive/api/reference/rest/v3/files/list with 4 parameters

 driveId=1MXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 supportsAllDrives=true
 includeItemsFromAllDrives=true
 corpora=drive

and receive answer - "message": "Shared drive not found: 1MXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",


Solution

  • When I checked your public folder 1M88r7TS5uZkDrWj-3SZ9AoQQtBXOfyPD, it seems that the folder is not in the shared drive. It's a shared folder in a user's drive. So, that value cannot be used for the drive ID. This is the reason for your current issue.

    Also, about I want to know FileID for each file, when I check the file and folder list of the shared folder, there are only folders. If you want to retrieve all folder IDs, please do the following steps at API Explorer of Method: files.list of Drive API v3.

    1. Put '1M88r7TS5uZkDrWj-3SZ9AoQQtBXOfyPD' in parents and trashed=false into q.
    2. Put 1000 into pageSize.
    3. Click the "Execute" button.

    By this, the metadata of 377 folders is retrieved.

    About btw, I set fields "nextPageToken,incompleteSearch,kind,files(id,name,kind,mimeType)" - and expected nextPageToken, but received nothing, when I tested your fields, the correct response was returned. This is for Drive API v3. If v2 was used, an error occurs. Please be careful about this. But, in this case of v3, the default returned values are nextPageToken,incompleteSearch,kind,files(id,name,kind,mimeType). So, even when the fields are not used, those values are returned. For example, if you want to return only id, name, mimeType without including nextPageToken, you can use files(id,name,mimeType) as the value of fields.

    Reference: