gpt4 book ai didi

ruby - Google Drive API 不列出我的驱动器中的文件 (Ruby)

转载 作者:数据小太阳 更新时间:2023-10-29 08:03:47 25 4
gpt4 key购买 nike

我正在开发一个 Ruby 程序来访问我的谷歌驱动器以获取我的文件。我想使用服务器到服务器的连接来避免人们接受权限,所以我使用为 Service Account Client ID 生成的 p12 key 。连接正常,但我成功插入了一个文件。

我的问题是当我尝试列出我的所有文件时:调用工作正常但我只得到 2 个文件:之前插入的文档和一个名为 “如何开始使用云端硬盘” 的 pdf (我还有很多其他文件,例如文档、电子表格、演示文稿、图片等...)。

我使用我的谷歌帐户创建了我的 key ,但我无法访问我的文件。此外,我在我的程序中插入的文档没有出现在我的文件中的谷歌驱动器中。

我是否遗漏了 API 的某些内容?我得到的是什么文件而不是我的文件?这真的就像我不在同一个 Google Drive 帐户上一样。这是我用来列出我的文件的代码:

# Prepare the OAuth client / Service Account 
client = Google::APIClient.new(application_name: 'Google Drive Ruby test', application_version: '0.0.1')
key = Google::APIClient::KeyUtils.load_from_pkcs12('key.p12', 'notasecret')
client.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => 'https://www.googleapis.com/auth/drive',
:issuer => '***@developer.gserviceaccount.com',
:signing_key => key)

client.authorization.fetch_access_token!

# Get the Drive API
drive = client.discovered_api('drive', 'v2')

# Upload a file
api_result = client.execute(
:api_method => drive.files.list,
:parameters => [])

非常感谢!

朱利安

最佳答案

啊,这就是问题所在。服务帐户不是您将通过浏览器更新的云端硬盘帐户。参见 Google Drive help required access to own Drive accountHow do I authorise an app (web or installed) without user intervention? (canonical ?) .顺便说一句,在你的代码中,files.list 上面的评论说“上传文件”,这就是我第一次错过它的原因:-)

关于ruby - Google Drive API 不列出我的驱动器中的文件 (Ruby),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29037883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com