【问题标题】:404 Resource Not Found: domain with Google Directory API404 资源未找到:使用 Google Directory API 的域
【发布时间】:2014-07-09 04:46:17
【问题描述】:

我按照快速入门并尝试使用 google-api-ruby-client 创建用户。

我已经在 google api 控制台中设置了访问权限。我可以使用 API 资源管理器让它工作。

但是当我尝试使用 ruby​​ 客户端时,我得到一个资源未找到:域错误。

代码如下:

def self.create_user

# Initialize the client.
client = Google::APIClient.new(
  :application_name => 'MYAPP',
  :application_version => '0.0.1'
)

# Authorization
# Load our credentials for the service account
key = Google::APIClient::KeyUtils.load_from_pkcs12(KEY_FILE, KEY_SECRET)

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/admin.directory.user',
  issuer: ACCOUNT_ID,
  signing_key: key)

# Request a token for our service account
client.authorization.fetch_access_token!

# Load API Methods
admin = client.discovered_api('admin', 'directory_v1')

# Make an API call.
result = client.execute(
   admin.users.update,
    name: { familyName: 'testy', givenName: 'testerson' },
     password: '!password12345!',
     primaryEmail: 'ttesterson@my-actual-domain.com'
)

result.data

结束

回复如下:

"error"=>{"errors"=>[{"domain"=>"global", "reason"=>"notFound", "message"=>"Resource Not Found: domain"}], "code"=>404, "message"=>"Resource Not Found: domain"}

为什么?

【问题讨论】:

  • 你还在运行这个应用程序吗?您对新的 Ruby API 有任何经验吗?由于明显缺少权限,我无法让示例工作。

标签: ruby google-admin-sdk google-directory-api


【解决方案1】:

在阅读了一些文档之后,我需要修复两件事。

  1. 我没有为我的测试服务帐户设置正确的授权。

您必须转到 Apps Console > Security > Advanced > Manage API client access 并为您的服务帐户添加客户端 URL 以及您要添加的任何特定权限

  1. 从这个问题中可以看出,您似乎需要创建一个用户对象,而不仅仅是传入参数。

这是我更新的代码:

# Authorization happens here ....

api = client.discovered_api('admin', 'directory_v1')
new_user = api.users.insert.request_schema.new(
    name: { familyName: 'Testy', givenName: 'Testerson' },
    primaryEmail: 'ttttesterson@<domain-redacted>.com',
    password: 'password123'
 )

  result = client.execute(
    api_method: api.users.insert,
    body_object: new_user
 )

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-02
    相关资源
    最近更新 更多