Python 谷歌驱动器API文件列表(maxResults=xxx)奇怪的行为
我正在尝试使用files.list()从驱动器获取所有文件。默认情况下,maxResults参数为100(按页)。为了加快工作速度,我尝试将maxResults增加到1000(如文档所示的最大值)。但它仍然返回100个结果 我想这是查询没有使用的参数,所以我尝试了一个小于100的值(例如:50),它会返回50个结果 我的问题是,是否有可能超过100页的结果 需要提到的是,我使用python中的API和服务帐户。对于凭据,我使用SignedJwtAssertionCredentials和一个子参数来访问要列出的驱动器 以下是我的代码摘录:Python 谷歌驱动器API文件列表(maxResults=xxx)奇怪的行为,python,google-drive-api,Python,Google Drive Api,我正在尝试使用files.list()从驱动器获取所有文件。默认情况下,maxResults参数为100(按页)。为了加快工作速度,我尝试将maxResults增加到1000(如文档所示的最大值)。但它仍然返回100个结果 我想这是查询没有使用的参数,所以我尝试了一个小于100的值(例如:50),它会返回50个结果 我的问题是,是否有可能超过100页的结果 需要提到的是,我使用python中的API和服务帐户。对于凭据,我使用SignedJwtAssertionCredentials和一个子参数
# -*- coding: utf-8 -*-
import json
import httplib2
from oauth2client.client import SignedJwtAssertionCredentials
from apiclient.discovery import build
with open('My\\path\\to\\key') as f:
dico_account = json.load(f)
credentials = SignedJwtAssertionCredentials(
dico_account['client_email'],
dico_account['private_key'],
scope=('https://www.googleapis.com/auth/drive',),
sub='johnsmith@mydomain.fr')
http = httplib2.Http(proxy_info=httplib2.ProxyInfo(httplib2.socks.PROXY_TYPE_HTTP,
'myproxydomain',
3030,
proxy_user='proxyuser',
proxy_pass='proxypass'))
credentials.get_access_token(http)
credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
filesAPI = drive_service.files()
result = filesAPI.list(maxResults=50, q='\'johnsmith@mydomain.fr\' in owners', fields='items(id,title,parents(id),permissions(role,emailAddress,id,type)),nextPageToken').execute()
print len(result['items'])
result = filesAPI.list(maxResults=500, q='\'johnsmith@mydomain.fr\' in owners', fields='items(id,title,parents(id),permissions(role,emailAddress,id,type)),nextPageToken').execute()
print len(result['items'])
正在印刷
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
50
100
>>>
它应该会起作用。请添加您的代码,以便我们进行检查。如果不进行查询,您是否仍会获得相同数量的文件?是的,我尝试了不使用q参数,但仍然得到100个结果。应该可以。请添加您的代码,以便我们进行检查。如果不进行查询,您是否仍会获得相同数量的文件?是的,我尝试了不使用q参数,但仍然得到100个结果。