未找到Ruby Google API资源:域

未找到Ruby Google API资源:域,ruby,google-api,Ruby,Google Api,通过从URL中删除.readonly,我成功地解决了下面的原始问题 我现在遇到了这个错误: {"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"notFound", "message"=>"Resource Not Found: domain"}], "code"=>404, "message"=>"Resource Not Found: domain"}} 再一次,我在网上查看了这个错误,但是所

通过从URL中删除.readonly,我成功地解决了下面的原始问题

我现在遇到了这个错误:

{"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"notFound", "message"=>"Resource Not Found: domain"}], "code"=>404, "message"=>"Resource Not Found: domain"}}
再一次,我在网上查看了这个错误,但是所有的链接似乎都指向Google上的错误页面,没有任何帮助来确定这个错误的修复方法

原版

我试图使用下面的脚本使用Ruby访问Google Directory API,但在执行脚本时收到一个错误

剧本

#!/usr/bin/env ruby
require 'rubygems'
require 'json'
require 'google/api_client'
require 'active_support/core_ext/hash'

# The value of client_email from the JSON file goes here
SERVICE_ACCOUNT_EMAIL = 'xxxxxxxxx-bk7gbhr8k2dfvtidm0cc0msnipo34c8p@developer.gserviceaccount.com'

# This should be an Admin
ACT_ON_BEHALF_EMAIL = 'xxxxxx@gmail.com'

# File path to the certificate
SERVICE_ACCOUNT_PKCS12_FILE_PATH = '/home/xxxx/3ce8a60d43a8fa5cb747441fdfd90c3b91d6f45b-privatekey.p12'

key = Google::APIClient::PKCS12.load_key(SERVICE_ACCOUNT_PKCS12_FILE_PATH, 'notasecret')

asserter = Google::APIClient::JWTAsserter.new(SERVICE_ACCOUNT_EMAIL, 'https://www.googleapis.com/auth/admin.directory.user.readonly', key)

client = Google::APIClient.new(:application_name => 'GAAccountAudit')

client.authorization = asserter.authorize(ACT_ON_BEHALF_EMAIL)

api = client.discovered_api('admin', 'directory_v1')

result = client.execute(
    :api_method => api.users.list,
    :parameters => {
        'domain' => 'http://www.xxxxxx.com',
        'orderBy' => 'givenName',
        'maxResults' => 500,
        'fields' => 'users(id,etag,primaryEmail,name,suspended)',
    }
)

users = JSON.parse(result.body, {:symbolize_names => true})[:users]

users.each do |u|
    puts "#{u[:name][:fullName]} <#{u[:primaryEmail]}>"
end

我已经读过这个错误,但我还没有找到一个结论性的答案。有人能告诉我如何解决这个错误吗?

你给服务帐户访问Google Apps帐户的权限了吗?@DaImTo你能告诉我怎么做吗?它可以编辑项目权限设置上的权限。
{"error" : "unauthorized_client","error_description" : "Unauthorized client or scope in request."}