GoogleDriveAPI上的所有教程website都有一个对象drive_service
,该对象之前已初始化到所提供的代码片段拾取的位置,但没有解释它是什么、做什么或应该如何构建。我正在使用Python
This is the example I am trying to do
我能够通过quickstart.py进行身份验证,没有任何问题
这是我的密码:
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)
以下是更多的例子:
我相信你的目标如下
service = build('drive', 'v3', credentials=creds)
中的service
和这些URL中的drive_service
之间的区别李>This is the example I am trying to do
和Here is my code:
李>对于这个问题,这个答案如何
一,。关于
service
和drive_service
:“Python快速入门”的
service
中的service = build('drive', 'v3', credentials=creds)
与这些URL中的drive_service
相同。因此service
包括使用API的授权(在本例中,它是驱动器API v3)。因此,可以修改“Python快速启动”的示例脚本,也可以将其用作授权脚本二,。
This is the example I am trying to do
的脚本:这是
This is the example I am trying to do
的示例脚本。此示例脚本将本地文件上载到Google Drive。在本例中,https://www.googleapis.com/auth/drive
用作作用域。这里有一点很重要。您可以看到从Quickstart复制和粘贴的授权脚本在本地文件夹中,已创建了作用域为
token.pickle
的https://www.googleapis.com/auth/drive.metadata.readonly
。运行快速启动脚本时,请将其删除,然后重新授权该作用域。这样,新的作用域将反映到访问令牌。请注意这一点。示例脚本:
MediaFileUpload
使用resumable=True
时,可以通过可恢复上载来上载大文件李>三,。{}的脚本:
这是
Here is my code
的示例脚本。此示例脚本将文件从Google Drive下载到本地PC。在本例中,https://www.googleapis.com/auth/drive
和/或https://www.googleapis.com/auth/drive.readonly
可以用作作用域。这里,作为一个测试用例,为了使用在上面第2节中创建的token.pickle
文件,范围没有从https://www.googleapis.com/auth/drive
更改。因此,您可以在不重新授权作用域的情况下使用脚本示例脚本:
fh = io.BytesIO()
修改为fh = io.FileIO("### filename ###", mode='wb')
李>注:
token.pickle
并重新授权作用域。请小心这个李>参考资料:
相关问题 更多 >
编程相关推荐