0

我正在尝试使用 google apis 的 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 和 api 客户端的 google 开发人员页面上都遵循了(略有不同的)示例,结果相同。这是两个实例的代码:

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!

在这两种情况下,我都尝试将访问变量设置为“storage”、“devstorage”、“storage.readonly”或“devstorage.readonly”,但也无济于事。

有任何想法吗?

谢谢!

4

0 回答 0