404资源未找到:具有Google Directory API的域 [英] 404 Resource Not Found: domain with Google Directory API

查看:80
本文介绍了404资源未找到:具有Google Directory API的域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了快速入门,正在尝试使用google-api-ruby-client创建用户.

I followed the quick start and am attempting to create a user using the google-api-ruby-client.

我已经在Google API控制台中设置了访问权限.而且我可以使用API​​资源管理器使它正常工作.

I've set up access in the google api console. And I can get this to work using the API explorer.

但是当我尝试使用ruby客户端时,却找不到资源:域错误.

But when I try using the ruby client, I'm getting a resource not found: domain error.

代码如下:

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"}

为什么?

推荐答案

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

After a bit of documentation reading, there were two things that I needed to fix.

  1. 我没有为我的测试服务帐户设置适当的授权.

您必须转到应用程序控制台>安全>高级>管理API客户端访问并添加您的服务帐户的客户端网址以及您要添加的任何特定权限

You have to go to the Apps Console > Security > Advanced > Manage API client access and add the client url for your service account as well as any specific permissions that you want to add

  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
 )

这篇关于404资源未找到:具有Google Directory API的域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆