Parsa Nikoo
Parsa Nikoo

Reputation: 155

Google drive get files with API-KEY

I use below url for get files

https://www.googleapis.com/drive/v2/files?name=xxx&key=yyy

But I get this error:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "forbidden",
    "message": "Insufficient permissions for this file",
    "locationType": "other",
    "location": "file.permissions"
   }
  ],
  "code": 403,
  "message": "Insufficient permissions for this file"
 }
}

I want get lists only with key

How I can?

Upvotes: 0

Views: 2825

Answers (1)

Tanaike
Tanaike

Reputation: 201693

I believe your goal as follows.

  • You want to retrieve the file list of Google Drive using your API key.
  • You want to achieve this using Drive API v2.

Issue and workaround:

The API key can be used for the public contents. So, unfortunately, you cannot all files on your Google Drive from the root folder using the API key. Because the root folder of Google Drive cannot be publicly shared. I thought that your error message might be due to this. (I'm not sure what you want to do using name=xxx. But, https://www.googleapis.com/drive/v2/files?key=yyy is trying to retrieve the file list of all files of Google Drive. In this case, such error occurs.) But, fortunately, when a folder in your Google Drive is publicly shared, the file list can be retrieved using the API key.

In this answer, I would like to introduce the method for retrieving the file list from the publicly shared folder in the Google Drive.

Sample endpoint:

When you test the following endpoint, please publicly share a folder in your Google Drive and use the folder ID of the folder. By this, the file list of the folder can be retrieved using the API key.

https://www.googleapis.com/drive/v2/files?q=%27folderId%27%20in%20parents&key=[YOUR_API_KEY]
  • In this endpoint, 'folderId' in parents is used as the search query. So, in this case, the folder of folderId is required to be publicly shared. When you use this script, please replace folderId to the folder ID of your folder which is publicly shared.

  • When Drive API v3 is used, you can use the following endpoint.

      https://www.googleapis.com/drive/v3/files?q=%27folderId%27%20in%20parents&key=[YOUR_API_KEY]
    

Note:

  • When you want to retrieve the file list including the subfolders with the folder structures, it is required to traverse the folders. In this case, I think that it is required to use the script.
  • This answer supposes that your API key can be used Drive API. Please be careful this.

References:

Upvotes: 4

Related Questions