下载文件google drive python

2024-06-15 22:38:02 发布

您现在位置:Python中文网/ 问答频道 /正文

如何从googledrive下载文件?在

我正在使用pydrive使用链接。在

#https://drive.google.com/open?id=DWADADDSASWADSCDAW
    from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive

gauth = GoogleAuth()
drive = GoogleDrive(gauth)

gdrive_file = drive.CreateFile({'id': 'id=DWADADDSASWADSCDAW'})
gdrive_file.GetContentFile('DWADSDCXZCDWA.zip') # Download content file.

错误:

^{pr2}$

Tags: 文件fromhttpsimportid链接drivefile
1条回答
网友
1楼 · 发布于 2024-06-15 22:38:02

请尝试documentation中提供的示例代码。在

The Drive API allows you to download files that are stored in Google Drive. Also, you can download exported versions of Google Documents (Documents, Spreadsheets, Presentations, etc.) in formats that your app can handle. Drive also supports providing users direct access to a file via the URL in the webViewLink property.

这是code snippet

file_id = '0BwwA4oUTeiV1UVNwOHItT0xfa2M'
request = drive_service.files().get_media(fileId=file_id)
fh = io.BytesIO()
downloader = MediaIoBaseDownload(fh, request)
done = False
while done is False:
    status, done = downloader.next_chunk()
    print "Download %d%%." % int(status.progress() * 100)

相关问题 更多 >