使用Google云端硬盘API从共享链接下载整个Google云端硬盘文件夹

时间:2015-05-20 09:31:56

标签: python-2.7 google-drive-api google-api-python-client

我有Google云端硬盘文件夹的共享链接。我想使用驱动器API下载整个文件夹。我现在这样做的方式是我得到一个孩子的列表'然后下载所有的孩子'实例进入文件夹。问题是,对于每个孩子来说,'实例下载,请求发送到googleapis。因此,如果有1000个文件,则发送1000个请求。我有一个包含超过10M小文件的文件夹,Google将请求数限制为每天10M。 我想知道是否有某种方式(驱动器api中的任何功能)一次下载整个文件夹? 这是我的代码:

storage = Storage(CredentialsModel, 'id', task_request.user, 'credential')
credential = storage.get()
http = httplib2.Http()
http = credential.authorize(http)
service = build('drive', 'v2', http=http)

file_list = []
children = service.children().list(folderId=folder_id, q=q, **param).execute()
for child in children.get('items', []):
    file_list.append(child['id'])

for k in range(len(file_list)):
    curr_file = service.files().get(fileId=file_list[k]).execute()
    download_url = curr_file.get('downloadUrl')
    if download_url:
        resp, content = service._http.request(download_url)

    if resp.status == 200:
        title = drive_file.get('title')
        path = title
        file = open(path, 'wb')
        file.write(content)

0 个答案:

没有答案