每当我尝试从Google Apps实例访问论坛时,都会收到以下回复:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "backendError",
"message": "Backend Error"
}
],
"code": 500,
"message": "Backend Error"
}
}
我正在使用的代码如下:
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(
'mydeveloperid@developer.gserviceaccount.com',
'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' => 'mygroup@mydomain.com', 'alt' => 'json' }
)
puts result.body
我已在Google Apps管理控制台和https://cloud.google.com/console内的“管理API客户端访问”中添加了正确的权限和所有权限。
我甚至注意到,当我使用“https://developers.google.com/admin-sdk/groups-settings/v1/reference/groups/get#try-it”时,它不会返回任何内容。
请帮帮我
答案 0 :(得分:1)
我终于使用git repo主页中的一些示例代码解决了我的问题。这就是我想出的:
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 => 'mydeveloperid@developer.gserviceaccount.com',
:person => 'myemail@mydomain.com',
:signing_key => key)
client.authorization.fetch_access_token!
groupssettings = client.discovered_api('groupssettings', 'v1')
result = client.execute(
:api_method => groupssettings.groups.get,
:parameters => { :groupUniqueId => 'mygroup@mydomain.com', :alt => 'json' }
)
puts result.body