我正在尝试使用Google Directory API编写一个为数千名用户创建邮件帐户的应用程序.逐个创建它们有效,但速度极慢.我尝试使用批处理请求,假设一次最多支持1000个请求.但是,只有大约50个用户成功创建,其余请求抛出403错误.如果我将批量大小更改为40,则在第一批之后,许多请求会因5xx错误而失败.
如果批量请求仍然受到相同速率限制的限制,那么似乎毫无价值,因为我可以以这么慢的速率单独发送这些请求.有没有更好的方法来做到这一点还是我应该做的其他事情呢?
我一直试图让服务帐户身份验证为Google Admin SDK工作几天,但无济于事.我正在使用谷歌新安装的google-api-python-client-1.2库.
我一直在关注该主题的Google文档.链接在这里:
HTPS://developers.google.com/accounts/docs/OAuth2ServiceAccount
HTPS://developers.google.com/api-client-library/python/guide/aaa_oauth
HTP://google-api-python-client.googlecode.com/hg/docs/epy/oauth2client.client.SignedJwtAssertionCredentials-class.html
并让tasks.py服务帐户示例正常工作,您可以在此处找到:
HTP://code.google.com/p/google-api-python-client/source/browse/samples/service_account/tasks.py R = c21573904a2df1334d13b4380f63463c94c8d0e8
并且一直在密切研究这两个相关主题的Stack Overflow线程:
google admin sdk目录api 403 python
使用Oauth2作为服务帐户(教育版)的Google管理员API - 403错误
并研究了gam.py(Dito GAM)中的相关代码.
然而,我仍然遗漏了一些东西,因为我在几乎每个编写的测试用例中都收到了'oauth2client.client.AccessTokenRefreshError:access_denied'异常.
以下是测试身份验证的简明示例:
import httplib2
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
f = file('myKey.p12', 'rb')
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
'myServiceAdmin@developer.gserviceaccount.com',
key,
sub='myAdminUser@my.googleDomain.edu',
scope = ['https://www.googleapis.com/auth/admin.directory.user',])
http = httplib2.Http()
http = credentials.authorize(http)
service = build('admin', 'directory_v1', http=http)
Run Code Online (Sandbox Code Playgroud)
当我运行上面的代码时,我得到了这个堆栈转储和异常:
Traceback (most recent call last):
File "./test.py", line 17, in <module>
service = build('admin', 'directory_v1', …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Directory API更新客户对象,但尝试修改顶级的任何内容会导致返回400(无效客户语言)错误.
这是初始对象的获取(一些项目是为隐私而编辑的)
请求
GET https://www.googleapis.com/admin/directory/v1/customers/<customerID>
Run Code Online (Sandbox Code Playgroud)
响应
200 OK
{
"kind": "admin#directory#customer",
"id": "<customerID>",
"etag": "\"<etag>\"",
"customerDomain": "<domainName>",
"alternateEmail": "<email>",
"postalAddress": {
"contactName": "<name>",
"organizationName": "",
"locality": "<city>",
"region": "<state>",
"countryCode": "US",
"addressLine1": "<address1>",
"addressLine2": "",
"addressLine3": "",
"postalCode": "<zip>"
},
"phoneNumber": "<phoneNumber>",
"language": "en",
"customerCreationTime": "2011-03-31T03:45:49.408Z"
}
Run Code Online (Sandbox Code Playgroud)
然后尝试单独更新电话号码或语言会导致错误.如果我使用补丁或更新呼叫并不重要.
电话号码补丁电话:
{
"phoneNumber": "+18005551234"
}
Run Code Online (Sandbox Code Playgroud)
语言补丁调用:
{
"language": "en-GB"
}
Run Code Online (Sandbox Code Playgroud)
补丁或更新呼叫响应
400 OK
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid Customer language"
}
],
"code": 400, …Run Code Online (Sandbox Code Playgroud) 我正在创建一个供内部使用的iOS应用程序.我们有一个Google域名.作为应用程序功能的一部分,我希望能够搜索该域中的所有用户.这已经可以在Gmail,Apple Mail应用程序和其他应用程序中完成.
我发现您可以使用Admin SDK for users.list来完成我想要做的事情.我为iOS应用程序创建了一个客户端ID,并授权我的应用程序执行users.list.
但是,现在我为使用OAuth2登录的用户收到权限错误:
我发现如果您委托具有权限,则可以创建一个服务帐户来代表您发出API请求.我不确定这是否是我想要做的事情,因为这似乎更像是安全服务器而不是应用程序.我也不确定这是如何与用户(来自我们的域)进行集成的,用户可以列出我们的用户.
是否可以纯粹通过OAuth /前端应用列出/搜索Google域中的用户?
我正在尝试从我的G-Suite目录中删除自定义架构。
GET https://www.googleapis.com/admin/directory/v1/customer/my_customer/schemas?fields=schemas(schemaId%2CschemaName)&key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)
响应:
{
"schemaId": "wAq9Qg4MR3-2Y647IvNb6w==",
"schemaName": "SSO",
"fields": [
{
"fieldId": "ZHzd3CDzQYmnEkJH9VDwhg==",
"fieldName": "awsRole",
"multiValued": true
}
]
}
Run Code Online (Sandbox Code Playgroud)
尝试使用该DELETE方法时,我得到以下信息:
DELETE https://www.googleapis.com/admin/directory/v1/customer/my_customer/schemas/SSO?key={YOUR_API_KEY}
Run Code Online (Sandbox Code Playgroud)
响应:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "invalid",
"message": "Invalid Input: ZHzd3CDzQYmnEkJH9VDwhg=="
}
],
"code": 400,
"message": "Invalid Input: ZHzd3CDzQYmnEkJH9VDwhg=="
}
}
Run Code Online (Sandbox Code Playgroud)
在重要的情况下,我会使用https://developers.google.com/apis-explorer/#s/admin/directory_v1/directory.schemas.delete,但尝试通过以下方式也会发生同样的情况:https : //developers.google .com / admin-sdk / directory / v1 / reference / schemas / delete。
我无法弄清楚我在做什么错。令人困惑的是,Invalid input错误中的指示fieldId与自定义架构中的对应。
如何从G …
我一直在尝试一些组合,但似乎无法想出一些有用的东西.有关我要问的API的更多信息,请访问https://developers.google.com/admin-sdk/directory/v1/reference/users/insert.我有一种感觉,我只是没有正确设置请求.已知下面的代码可以工作.我用它来设置能够查询所有用户的客户端.
client = Google::APIClient.new(:application_name => "myapp", :version => "v0.0.0")
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 => issuer,
:signing_key => key,
:person => user + "@" + domain)
client.authorization.fetch_access_token!
api = client.discovered_api("admin", "directory_v1")
Run Code Online (Sandbox Code Playgroud)
当我尝试使用以下代码时
parameters = Hash.new
parameters["password"] = "ThisIsAPassword"
parameters["primaryEmail"] = "tstacct2@" + domain
parameters["name"] = {"givenName" => "Test", "familyName" => "Account2"}
parameters[:api_method] = api.users.insert
response = client.execute(parameters)
Run Code Online (Sandbox Code Playgroud)
我总是得到相同的错误"代码":400,"消息":"无效的给定/姓氏:FamilyName"
在研究这个特定的API时,我发现了一些事情.如果我打印出列表和插入函数的参数,例如
puts "--- Users List ---"
puts api.users.list.parameters
puts "--- Users Insert …Run Code Online (Sandbox Code Playgroud) 我正在尝试通过管理 SDK 更新一些用户数据。我以为这会起作用
function directoryUpdate(userId, userDept, userLocation, userPhone, userTitle) {
var update = {
organizations:
{
name: "Next Step Living",
title: userTitle,
primary: true,
type: "work",
department: userDept,
location: userLocation
},
phones:
{
value: userPhone,
type: "work",
primary: true,
}
};
update = AdminDirectory.Users.update(update, userId);
Logger.log('User %s updated with result %s.', userId, update)
return true;
}
Run Code Online (Sandbox Code Playgroud)
但它不会更新记录中的组织或电话数据。它也不会抛出任何类型的错误。
三个问题,执行此更新的正确语法是什么,我认为它的工作方式类似于 API 更新,并且行为类似于更新插入,这是真的吗?以及在更新期间捕获任何错误的最佳实践是什么。我想在更新失败时返回 false 并捕获该信息。在此先感谢您的帮助。
我已经阅读了 Admin ADK Directory API 文档中的所有相关页面以及 stackoverflow 上的几个问题,但我仍然陷入困境。
我是我的 Google Apps 域的超级管理员,我希望我的域中的用户能够创建自己的 Google 网上论坛。我制作了一个 Google 表单,用户可以在其中指定群组的名称和电子邮件。然后,Google 表单响应表有一个“表单提交时”触发器,它调用我的代码来创建组。
createGroupTest()当我从脚本编辑器运行时,此代码有效。它会立即在我的 Google Apps 域中创建该组。
当“表单提交”触发器运行该函数时,此代码不起作用onFormSubmit(e)。catch(e)我收到了来自俗语的电子邮件Exception: Failed to authenticate for service: Groups。
有谁知道是什么导致 oauth 身份验证在脚本编辑器中工作,但在 onFormSubmit 函数调用时却不起作用?
function onFormSubmitTest() {
var t = new Date();
t = t.getTime();
onFormSubmit([t, "AAA Test Group " + t], ["aaa.testgroup." + t + "@mydomain.com"], ["me@mydomain.com"]);
}
var consumerKey = "mydomain.com";
var consumerSecret = "xxxxxxxxxxxxxxxxxxxxxxxx";
var domainName = "mydomain.com";
function …Run Code Online (Sandbox Code Playgroud) google-apps google-apps-script oauth-2.0 google-admin-sdk google-directory-api
我正在使用Google Admin SDK API管理我们组织的Google应用程序帐户中的用户(创建/更新)。我们允许用户选择使用2要素身份验证功能,并且当我们的内部支持代表之一查询他们的帐户时,我希望能够确定是否启用了该帐户。查看https://developers.google.com/admin-sdk/directory/v1/reference/users上的文档,我看不到任何表明该设置的属性。
我是否可以通过其他方法检查是否通过API启用了它?
我正在尝试访问 dbm api ,我正在使用服务帐户验证 url,请查找下面的示例代码
from oauth2client.service_account import ServiceAccountCredentials
from apiclient.discovery import build
from httplib2 import Http
scopes =['https://www.googleapis.com/auth/doubleclickbidmanager']
credentials = ServiceAccountCredentials.from_json_keyfile_name(
'path/to/key/.jsonfile', scopes=scopes)
http_auth = credentials.authorize(Http())
body={}
dbm = build('doubleclickbidmanager', 'v1', http=http_auth)
print dbm
request = dbm.lineitems().downloadlineitems(body=body).execute()
print request
Run Code Online (Sandbox Code Playgroud)
如果我使用oauth机制来验证 url,则代码可以正常运行,因为我不需要用户交互,所以我需要服务器到服务器机制,所以我使用了服务帐户
我尝试过的步骤:
我已经创建了服务帐户并下载了json密钥文件并在代码中使用,但是当我尝试运行我的代码时,它会抛出以下错误:
googleapiclient.errors.HttpError: <HttpError 403 when requesting https://www.googleapis.com/doubleclickbidmanager/v1/lineitems/downloadlineitems?alt=json returned "You are not authorized to use DoubleClick Bid Manager API. Please contact dbm-support@google.com.">
Run Code Online (Sandbox Code Playgroud)
请帮忙,提前致谢。
python google-api service-accounts google-admin-sdk double-click-advertising
google-admin-sdk ×10
google-api ×2
oauth ×2
google-apps ×1
ios ×1
oauth-2.0 ×1
python ×1
python-2.7 ×1