Reputation: 3694
When running this list files there is not a nextPageToken
there is just files[]
.
curl \
'https://www.googleapis.com/drive/v3/files?fields=files(id%2C%20name)&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
result:
{
"files": [
{
"id": "1",
"name": "1"
},
...
{
"id": "2",
"name": "2"
}
]
}
Leaving the fields
parameter empty, the nextPageToken
is returned.
curl \
'https://www.googleapis.com/drive/v3/files?key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
result:
{
"kind": "drive#fileList",
"nextPageToken": "~!!~AI9FV7TN...",
"incompleteSearch": false,
"files": [
{
"kind": "drive#file",
"id": "1",
"name": "1",
"mimeType": "application/vnd.google-apps.spreadsheet"
},
...
Is this a bug or is there some way to get the nextPageToken
and limit the fields returned? The doc page for fields
implies that it should work:
Note: The Drive API supports query parameters for data pagination (maxResults and nextPageToken). For APIs that support these parameters, use these parameters to reduce the results of each query to a manageable size. Otherwise, the performance gains possible with partial response might not be realized.
Upvotes: 5
Views: 1102
Reputation: 201553
When fields=files(id,name)
is used for the method of "Files: list", the file ID and filename are returned. In this case, the values of fields are files.id
and files.name
. nextPageToken
is not included in fields
. By this, the page token is not returned. When fields
is not used, it seems that fields
of nextPageToken,incompleteSearch,kind,files(id,name,kind,mimeType)
is the default value. So I thought that this is not a bug, and it might be the current specification.
So when you want to retrieve nextPageToken
when you use https://www.googleapis.com/drive/v3/files?fields=files(id%2C%20name)
, please include nextPageToken
in fields
as follows.
curl \
'https://www.googleapis.com/drive/v3/files?fields=nextPageToken%2Cfiles%28id%2Cname%29&key=[YOUR_API_KEY]' \
--header 'Authorization: Bearer [YOUR_ACCESS_TOKEN]' \
--header 'Accept: application/json' \
--compressed
fields
is nextPageToken,files(id,name)
.When above curl command is run, the following result is returned.
{
"nextPageToken": "###",
"files": [
{"id": "###", "name": "###"},
{"id": "###", "name": "###"},
,
,
,
]
}
Upvotes: 7