Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/359.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Google Drive API列表文件仅列出10个文件_Python_Google Drive Api - Fatal编程技术网

Python Google Drive API列表文件仅列出10个文件

Python Google Drive API列表文件仅列出10个文件,python,google-drive-api,Python,Google Drive Api,我正在尝试编写一个Python脚本,使用GoogleDriveV3API列出GoogleDrive文件夹中的文件。作为第一步,我一直在尝试列出驱动器中的所有文件。当在GoogleAPI文档页面上使用“trythisapi”功能进行测试时,它可以工作,但是,我的Python脚本只列出了10个文件,nextPageToken没有被更改。这是我写的代码: page_token = None while True: response = service.files().list(pageSize

我正在尝试编写一个Python脚本,使用GoogleDriveV3API列出GoogleDrive文件夹中的文件。作为第一步,我一直在尝试列出驱动器中的所有文件。当在GoogleAPI文档页面上使用“trythisapi”功能进行测试时,它可以工作,但是,我的Python脚本只列出了10个文件,nextPageToken没有被更改。这是我写的代码:

page_token = None
while True:
    response = service.files().list(pageSize=1000,fields="nextPageToken, files(id, name)",pageToken=page_token).execute()
    for file in response.get('files', []):
        print('Found file: %s (%s)' % (file.get('name'), file.get('id')))
    page_token = response.get('nextPageToken', None)
    if page_token is None:
        break

我已尝试将pageSize更改为不同的值,但由于某些原因,我无法让脚本列出超过10个文件,其中Google API文档中的“试用”功能列出了我的所有文件。

如果将pageSize设置为小于10的值,它是否成功获取下一页?我只是尝试将pageSize设置为5,我还收到了10份文件。10份在同一页?或者它成功地转到下一页了吗?有没有好的方法来判断文件是否在同一页内?您是否尝试过file.get('nextPageToken')并查看其中的实际内容。