0

I'm trying to use the ruby client for google apis to access cloud storage and invariably I get the following error:

/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"
}

I've followed the (slightly different) examples both on github and the google developers pages for the api client with the same result. Here's the code from both instances:

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

I also get the same error if I try....

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!

In both cases I've tried setting the access variable to 'storage', 'devstorage', 'storage.readonly' or 'devstorage.readonly' also to no avail.

Any ideas?

Thanks!

Stuart M
  • 11,458
  • 6
  • 45
  • 59
Lee
  • 25
  • 6
  • 1
    OK, after several hours of banging my head against the monitor I finally figured it out. The 'access' variable should read "devstorage.read_only". – Lee Apr 21 '13 at 19:08
  • Great thanks, this worked for me also. Serves me right from cutting and pasting from the Google docs https://code.google.com/p/google-api-ruby-client/wiki/ServiceAccounts – Xian Aug 16 '13 at 10:43
  • I'm emulating your steps but I get Google::APIClient - Please provide :application_name and :application_version when initializing the client ArgumentError: Invalid keyfile or passphrase any help? – wachichornia Dec 05 '13 at 22:50

0 Answers0