Google目录API插入用户
Google Directory API insert user
我真的很难尝试用这个 API 添加新用户。我正在按照 google 目录文档中的每一步进行操作,但我失败了。
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
# Setup the Admin SDK Directory API
SCOPES = 'https://www.googleapis.com/auth/admin.directory.user'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('admin', 'directory_v1', http=creds.authorize(Http()))
# Call the Admin SDK Directory API
#Insert User
body = { "name":
{"familyName": "Test", "givenName": "Mahalo"},
"password": "mahalo@test",
"primaryEmail": "test@test.com",
}
user_add = service.users().insert(body=body).execute()
当我尝试 insert 方法时出现此错误
googleapiclient.errors.HttpError: https://www.googleapis.com/admin/directory/v1/users?alt=json returned "Domain not found.">
如果我尝试 运行 像快速入门指南中那样的 list 方法,它 运行 是完美的
https://developers.google.com/admin-sdk/directory/v1/quickstart/python
只需将我的主要电子邮件更改为 "primaryEmail": "test@mydomain.com"
我真的很难尝试用这个 API 添加新用户。我正在按照 google 目录文档中的每一步进行操作,但我失败了。
from __future__ import print_function
from apiclient.discovery import build
from httplib2 import Http
from oauth2client import file, client, tools
# Setup the Admin SDK Directory API
SCOPES = 'https://www.googleapis.com/auth/admin.directory.user'
store = file.Storage('credentials.json')
creds = store.get()
if not creds or creds.invalid:
flow = client.flow_from_clientsecrets('client_secret.json', SCOPES)
creds = tools.run_flow(flow, store)
service = build('admin', 'directory_v1', http=creds.authorize(Http()))
# Call the Admin SDK Directory API
#Insert User
body = { "name":
{"familyName": "Test", "givenName": "Mahalo"},
"password": "mahalo@test",
"primaryEmail": "test@test.com",
}
user_add = service.users().insert(body=body).execute()
当我尝试 insert 方法时出现此错误
googleapiclient.errors.HttpError: https://www.googleapis.com/admin/directory/v1/users?alt=json returned "Domain not found.">
如果我尝试 运行 像快速入门指南中那样的 list 方法,它 运行 是完美的
https://developers.google.com/admin-sdk/directory/v1/quickstart/python
只需将我的主要电子邮件更改为 "primaryEmail": "test@mydomain.com"