【发布时间】:2021-04-01 10:02:52
【问题描述】:
正如标题所说,我对 pydrive 有疑问。我运行了 pydrive 快速入门 (https://googleworkspace.github.io/PyDrive/docs/build/html/quickstart.html) 中给出的代码,并创建了一个设置和凭据文件,以避免一直输入我的凭据。 但是当我运行这段代码时:
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
# Rename the downloaded JSON file to client_secrets.json
# The client_secrets.json file needs to be in the same directory as the script.
gauth = GoogleAuth()
drive = GoogleDrive(gauth)
# List files in Google Drive
fileList = drive.ListFile().GetList()
for drive_file in fileList:
print('title: %s, id: %s' % (drive_file['title'], drive_file['id']))
我只能看到使用我的脚本创建的文件。例如,如果我在列表文件之前添加这个:
folder = drive.ListFile({'q': "title = 'Python_test' and trashed=false"}).GetList()[0] # get the folder we just created
file = drive.CreateFile({'title': "test.txt", 'parents': [{'id': folder['id']}]})
file.Upload()
我只看到我刚刚创建的文件夹和文件 ID...如果我在我的驱动器上手动添加一个文件(例如在我的浏览器上),它不会出现。
有人知道发生了什么吗?
【问题讨论】:
-
您有 GoogleAuth 的代码吗?它要求什么范围?
-
@DaImTo 哦,这只是一个范围请求问题,谢谢! (我在设置文件中添加了错误的 oauth_scope)
标签: python google-drive-api pydrive