Jason Barnett
Jason Barnett

Reputation: 195

Google Apps Groups Settings API :: 500 Backend Error

Whenever I attempt to access the groups from our Google Apps instance, I get the following response:

{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "backendError",
    "message": "Backend Error"
   }
  ],
  "code": 500,
  "message": "Backend Error"
 }
}

The code I am using is below:

begin
  require 'google/api_client'
rescue LoadError
  puts "You need the google-api-ruby-client gem..."
  puts "$ gem install google-api-client"
  exit 1
end

client = Google::APIClient.new(application_name: "Group Modifier")

## Use key to authenticate and generate token
key = Google::APIClient::PKCS12.load_key("#{File.dirname(__FILE__)}/mykey.p12", 'notasecret')
service_account = Google::APIClient::JWTAsserter.new(
  '[email protected]',
  'https://www.googleapis.com/auth/apps.groups.settings',
  key)

client.authorization = service_account.authorize

groupssettings = client.discovered_api('groupssettings', 'v1')

result = client.execute(
    :api_method => groupssettings.groups.get,
    :parameters => { 'groupUniqueId' => '[email protected]', 'alt' => 'json' }
)

puts result.body

I've added the correct permissions and all of that in both the "Manage API client access" within the Google Apps Admin Console and within the https://cloud.google.com/console.

I even noticed that when I use the "https://developers.google.com/admin-sdk/groups-settings/v1/reference/groups/get#try-it" it doesn't return anything.

Please help me out

Upvotes: 0

Views: 987

Answers (1)

Jason Barnett
Jason Barnett

Reputation: 195

I finally resolved my problem with using some example code from the git repo homepage. This is what I came up with:

begin
  require 'google/api_client'
rescue LoadError
  puts "You need the google-api-ruby-client gem..."
  puts "$ gem install google-api-client"
  exit 1
end

client = Google::APIClient.new

key = Google::APIClient::KeyUtils.load_from_pkcs12("#{File.dirname(__FILE__)}/mykey.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/apps.groups.settings',
  :issuer => '[email protected]',
  :person => '[email protected]',
  :signing_key => key)
client.authorization.fetch_access_token!

groupssettings = client.discovered_api('groupssettings', 'v1')

result = client.execute(
    :api_method => groupssettings.groups.get,
    :parameters => { :groupUniqueId => '[email protected]', :alt => 'json' }
)

puts result.body

Upvotes: 1

Related Questions