Google drive API files list size <= 100 when specify fields parameter

When i specify fields parameter in files list request, i only get 100 records of files in response. But in API documentation written about pageSize parameter: "The maximum number of files to return per page. Partial or empty result pages are possible even before the end of the files list has been reached. Acceptable values are 1 to 1000, inclusive. (Default: 100)".

curl \
  'https://www.googleapis.com/drive/v3/files?pageSize=500&fields=nextPageToken%2Cfiles(id%2C%20name%2C%20parents%2C%20mimeType%2C%20owners%2C%20permissions)' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

only 100 records max in response

Upvotes: 0

Views: 2684

Answers (1)

Jose Vasquez
Jose Vasquez

Reputation: 1738

As a workaround I'd avoid using "fields" parameter if a wanted to retrieve 1000 items

There's already a public report regarding this: https://issuetracker.google.com/issues/154155376

This is normal due to the limit of characters. The limit is dependent on both the server and the client used so when it comes to add more characters, Drive API will try to reduce the characters length sent in the payload.

In a summary, you should reduce the size of files to retrieve if those fields are mandatory.

The documentation says pageSize -> The maximum number of files to return per page. Partial or empty result pages are possible even before the end of the files list has been reached. Acceptable values are 1 to 1000, inclusive. (Default: 100)

If you find this to be a blocker for your application, Google recommends to use Google Issue Tracker in order to report a bug or ask for a new feature.

As a different approach specify the pageToken in your requests

By following your request template, here are the changes:

curl \
  'https://www.googleapis.com/drive/v3/files?pageSize=100&pageToken=[TOKEN]&fields=nextPageToken, files(id, name, parents, mimeType, owners, permissions)' \
  --header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
  --header 'Accept: application/json' \
  --compressed

As I mentioned before due to the HTTP limitations on server side use the page nextPageToken that you get in the response and request 100 items so you can avoid these limitations.

Keep in mind that this approach will need more requests than before.

Upvotes: 2

Related Questions