谷歌云存储:授权失败。服务器消息:“错误”:“无效范围”

时间:2013-04-21 17:15:30

标签: ruby google-api-ruby-client

我正在尝试使用goy api的ruby客户端访问云存储,并且我总是遇到以下错误:

/usr/local/lib/ruby/gems/1.9.1/gems/signet-0.4.5/lib/signet/oauth_2/client.rb:875:in `fetch_access_token': Authorization failed.  Server message: (Signet::AuthorizationError)
{
  "error" : "invalid_scope"
}

我在github和google开发者页面上都遵循了(略有不同)的例子,为api客户端提供了相同的结果。这是两个实例的代码:

require 'google/api_client'

apiClient = Google::APIClient.new({'application_name' => 'myApp'})

key    = Google::APIClient::PKCS12.load_key('client.p12', 'notasecret')
client = "xxxxxxxxxxxx@developer.gserviceaccount.com"
api    = "https://www.googleapis.com/auth/"
access = "devstorage.readonly"

service_account = Google::APIClient::JWTAsserter.new(client, api+access, key)
client.authorization = service_account.authorize

如果我尝试,我也会得到同样的错误。

require 'google/api_client'

apiClient = Google::APIClient.new({'application_name' => 'myApp'})

key    = Google::APIClient::KeyUtils.load_from_pkcs12('client.p12', 'notasecret')
client = "xxxxxxxxxxxx@developer.gserviceaccount.com"
api    = "https://www.googleapis.com/auth/"
access = "devstorage.readonly"

apiClient.authorization = Signet::OAuth2::Client.new(
:token_credential_uri => 'https://accounts.google.com/o/oauth2/token',
:audience => 'https://accounts.google.com/o/oauth2/token',
:scope => "#{api}#{access}",
:issuer => client,
:signing_key => key)

apiClient.authorization.fetch_access_token!

在这两种情况下,我都尝试将 access 变量设置为'storage','devstorage','storage.readonly'或'devstorage.readonly'也无济于事。

有什么想法吗?

谢谢!

0 个答案:

没有答案