3

我在使用 Google Drive API 时遇到了一些非常奇怪的问题。

在这里忍耐一下,有很多要解释的。

我最初使用我的一个 Google 帐户使 API 工作——test@google.com为简单起见,我们称之为它。我让 Google Picker UI 正常工作,它正确显示了我的云端硬盘帐户中的文件列表。

我将它设置为我的 APP_ID,并且我有一些服务器端逻辑,它使用官方gem 使用端点google-ruby-api-client连接到 Drive API 。drive.files.get然后我可以使用以下代码段下载文件的元数据:

require 'google/api_client'

client = Google::APIClient.new

# client ID and secret from Google APIs Console
client.authorization.client_id = "{CLIENT_ID}"
client.authorization.client_secret = "{SECRET}"
client.authorization.redirect_uri = "http://myapp.com/users/auth/gdrive"
# access token stored in database from oauth2 flow
client.authorization.access_token = "TOKEN"

client.authorization.scope = [
  "https://www.googleapis.com/auth/drive.file",
  "https://www.googleapis.com/auth/userinfo.email",
  "https://www.googleapis.com/auth/userinfo.profile"
]
result = client.execute!(
  :api_method => 'drive.files.get',
  :version => 'v2',
  :parameters => { 'fileId' => params[:file_id] })

使用test@google.com我尝试过的帐户,结果返回文件的元数据,我可以下载文件。都是桃色的。

当我使用不同的Google 帐户时,问题就来了。我可以访问 Picker 中的文件,但是当fileId使用上述方法将请求发送到服务器时,我只是不断收到 404 错误,说文件不存在。我还尝试使用 google 提供的 OAuth 2.0 Playground 访问文件的元数据,但奇怪的是我仍然收到该错误,但我在使用该test@google.com帐户时也收到相同的 404 错误。

我唯一能真正想到的是,我提交了一个包含所有 Google Drive 详细信息的应用程序版本,并通过 Chrome Webstore 安装了该应用程序。在我意识到它作为一个启用驱动器的应用程序向所有人显示后,我立即将其删除并将 manifest.json 文件更改回其正常的非驱动器启用状态。我确实读到您应该通过 Chrome Webstore 安装该应用程序才能正常工作,但我也读到情况不再如此。您安装的 Chrome Webstore 应用程序是否存储在 Google 的云端某处,以便他们知道它是为特定帐户安装的?还是只是在本地安装了网络商店应用程序?我很混乱。

我在这里想念什么?我已经很久没有对 API 感到如此沮丧了。请帮忙!

4

1 回答 1

1

感谢 Ali Afshar 的回答——解决方案(目前)是暂时使用 Google Drive 的全部范围,而不仅仅是drive.file范围。

例如,而不是使用这个范围,

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

改用这个:

https://www.googleapis.com/auth/drive
于 2012-07-13T17:56:43.473 回答