问题
Using the drive api drive.files.list for the photos space is returning empty file lists. If I do not specify a space, I get a list of files, some of which are members of both the drive and photos spaces, as shown here:
Query:
GET https://www.googleapis.com/drive/v3/files?pageSize=1000&fields=files&key={YOUR_API_KEY}
Response (lots of file metadata, including files with 'spaces' property like this):
..."spaces": ["photos","drive"],...
However if I query looking for files from the 'photos' space, I get this:
Query:
GET https://www.googleapis.com/drive/v3/files?pageSize=1000&spaces=photos&fields=files&key={YOUR_API_KEY}
Response:
{"files": []}
So it seems I have the permissions correct since it will return to me all file information if 'space' is not specified, however adding the filter constraint of 'photos' to the 'space' property causes no file metadata to be returned (empty list).
This feature worked for the last couple of years, and recently seems to have broken.
Any hints appreciated!
回答1:
In the current stage, photos space is introduced as deprecated.
(DEPRECATED) The photos space includes all images and videos uploaded to Google Photos.
Ref: https://developers.google.com/drive/v3/web/about-organization#spaces
Because Google Photos was updated recently. (About this, you may have already known.) By this update, files in Google Photos are retrieved by the Drive API's endpoint without spaces=photos
. If you want to retrieve only files in Google Photos, please use q
.
If you can see the folder of "Google Photos" on your Google Drive
You can retrieve files in Google Photos using folder ID as follows.
GET https://www.googleapis.com/drive/v3/files?q=%22### folder ID of Google Photos ###%22+in+parents&key={YOUR_API_KEY}
If you cannot see the folder of "Google Photos"
From your question, you may have already done the following setting. If you have already done, please ignore this.
If you cannot see the folder of "Google Photos", please access to https://support.google.com/photos?p=drive, and check the document. When Google Drive is enabled, you can see the folder and retrieve the folder ID. In this situation, files and folders in "Google Photos" become "spaces": ["drive"]
.
If I misunderstand your situation, I'm sorry.
来源:https://stackoverflow.com/questions/48878186/google-drive-api-returns-empty-list-to-queries-on-photos-space