微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我只能看到用我的脚本 pydrive 创建的文件

如何解决我只能看到用我的脚本 pydrive 创建的文件

正如标题所说,我的 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...如果我在我的驱动器上手动添加一个文件(例如在我的浏览器上),它不会出现。

有人知道发生了什么吗?

解决方法

我刚刚发现问题,是在我的 settings.yaml 文件中,我只添加了这个 oauth_scope:

oauth_scope:
  - https://www.googleapis.com/auth/drive.file

但这只能访问应用程序创建的文件。为了纠正我需要像这样删除 .file

oauth_scope:
  - https://www.googleapis.com/auth/drive

如果您想了解有关不同范围的更多详细信息,请查看此链接: https://developers.google.com/identity/protocols/oauth2/scopes

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。