Reputation: 155
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
Reputation: 201693
I believe your goal as follows.
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.
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]
Upvotes: 4