未找到Ruby Google API资源:域

时间:2014-06-17 11:00:58

标签: ruby google-api

我已成功通过从网址中删除.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

错误

{"error" : "unauthorized_client","error_description" : "Unauthorized client or scope in request."}

我已经读过这个错误,但我无法找到一个确凿的答案。有人可以建议我如何解决这个错误吗?

0 个答案:

没有答案