Google Drive API Files.list(maxResults = xxx)奇怪的行为

时间:2016-01-15 08:16:31

标签: 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
>>> 

0 个答案:

没有答案