我正在尝试使用Google Admin SDK的Java客户端,特别是Directory API.它基于GoogleCredentials的使用,就像Google Drive API一样.但是,与谷歌驱动器不同的是,我收到了400 - 目录中的错误请求错误.我按如下方式设置API:
Directory directory = new Directory.Builder(TRANSPORT, FACTORY, credential).build();
Directory.Users.List list = directory.users().list();
Users users = list.execute();
Run Code Online (Sandbox Code Playgroud)
最后一个execute()生成列在帖子底部的错误和堆栈跟踪.我正在使用以下范围来授权自己.我也可以使用Drive API.
https://www.googleapis.com/auth/userinfo.profile
https://www.googleapis.com/auth/userinfo.email
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/admin.directory.user
Run Code Online (Sandbox Code Playgroud)
访问Drive API就像魅力一样.我可以毫无问题地请求文件.但是,如果我对Directory API执行简单操作,则会收到下面列出的错误和堆栈跟踪.我应该提一下,Drive API和Directory API都指向我是管理员的相同Google Apps域.我还在Google API控制台中启用了这两个API.对于其他人,我无法弄清楚我做错了什么,我想知道是否有其他人看到类似的东西,或者有其他经验通过Java客户端访问这个API.
谢谢,
拉尔夫
[ERROR] com.google.api.client.googleapis.json.GoogleJsonResponseException: 400 OK
[ERROR] {
[ERROR] "code" : 400,
[ERROR] "errors" : [ {
[ERROR] "domain" : "global",
[ERROR] "message" : "Bad Request",
[ERROR] "reason" : "badRequest"
[ERROR] } ],
[ERROR] "message" : "Bad Request"
[ERROR] }
[ERROR] at com.google.api.client.googleapis.json.GoogleJsonResponseException.from(GoogleJsonResponseException.java:145)
[ERROR] …Run Code Online (Sandbox Code Playgroud) 我已经阅读了 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启用了它?
我正在尝试编写一个与我们的Google Apps域中的组织单位配合使用的命令行脚本.因此,使用Google提供的许多复杂文档,我已成功在API控制台中创建了应用程序,打开了Admin SDK,并在我的脚本中成功连接.但是,当我创建目录服务对象(似乎是成功的)时,我遇到了与它交互的问题,因为我收到了该消息.我也安装了Python API包.这是我目前的代码:
import argparse
import httplib2
import os
import sys
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
f = file("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-privatekey.p12", "rb")
key = f.read()
f.close()
credentials = SignedJwtAssertionCredentials(
"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx@developer.gserviceaccount.com",
key,
scope = "https://www.googleapis.com/auth/admin.directory.orgunit"
)
http = httplib2.Http()
http = credentials.authorize(http)
directoryservice = build("admin", "directory_v1", http=http)
orgunits = directoryservice.orgunits()
thelist = orgunits.list('my_customer')
Run Code Online (Sandbox Code Playgroud)
当我运行该代码时,我收到错误消息:
Traceback (most recent call last):
File "test.py", line 33, in <module>
orgunits.list('my_customer')
TypeError: method() takes exactly 1 argument (2 given)
Run Code Online (Sandbox Code Playgroud)
我尝试没有使用"my_customer"别名,但后来错误抱怨我没有提供它.任何帮助将不胜感激,我很长一段时间没有使用Python; 它很可能是用户错误.
我要提前道歉,因为我可能会丢失一些信息,以便让任何人知道我的设置是正确的。请让我知道我还需要指定什么。我在一所大学工作,我们通过 Google 托管学生电子邮件帐户。他们经常忘记密码并不得不重置密码。如果他们验证了足够的有关自己的信息,我们有一个页面可以设置他们的密码。Google 已弃用我们一直使用的代码,转而使用他们的 Directory API。我的任务是转换这个旧代码:
//changes a password
@Override
public void reset ( final String username, final String password ) throws ResetException
{
try
{
Validate.notEmpty( username );
Validate.notEmpty( password );
final AppsForYourDomainClient client = ClientFactory.getClient(); //admin-user account
final UserEntry entry = client.retrieveUser( username );
Validate.isTrue( !entry.getLogin().getSuspended(), "Account is suspended." );
entry.getLogin().setPassword( password );
client.updateUser( username, entry );
}
catch ( final Exception e )
{
throw new ResetException( e );
}
}
Run Code Online (Sandbox Code Playgroud)
使用他们的新 API 进行一些操作。我读过很多文档和几个示例,但似乎没有一个有帮助。我已通过他们的管理控制台为我们的管理员帐户启用了 Admin SDK,并注册了我的应用程序并从他们的开发人员控制台获取了密钥,但我似乎无法收到任何返回我想要的内容的请求。现在我只是想获取用户列表:
public …Run Code Online (Sandbox Code Playgroud) 从 A 点开车到 B 点时,我必须获得通行费的数量。我为此使用了谷歌方向 API。API 在 html_instructions 标签中提供信息天气这条路是否收费公路作为响应,但收费公路可能包含收费数字,有没有办法计算它们。
我的团队目前正在开发一个应用程序,以使用 Admin SDK 在 GCP 中列出我公司的域用户,以用于入职和离职目的。
我们使用服务帐户来执行此操作,并且已admin.directory.user.readonly在 Google 管理员的高级设置中添加了范围。Admin SDK API 已激活,我们可以在 Credentials 区域中看到服务帐户。
当我们使用参数和 调用https://www.googleapis.com/admin/directory/v1/usersviewType=domain_public端点并使用oauth2ldomain=[our domain]生成的访问令牌时,我们会收到以下消息:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "Not Authorized to access this resource/api"
}
],
"code": 403,
"message": "Not Authorized to access this resource/api"
}
}
Run Code Online (Sandbox Code Playgroud)
是否存在我们没有预见到的任何域限制?
google-api service-accounts google-admin-sdk google-directory-api google-cloud-platform
我们使用 Python 从特定 G Suite 托管域中获取所有用户,但在完成以下教程并授予服务帐户所需的所有访问权限后,以下代码段仍会生成“未授权访问此资源/api:
import json
from google.oauth2 import service_account
from googleapiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/admin.directory.user.readonly']
credentials = service_account.Credentials.from_service_account_file("/path/to/file.json", scopes=SCOPES)
service = build('admin', 'directory_v1', credentials=credentials)
Run Code Online (Sandbox Code Playgroud) 使用Google方向API v3,您可以在同一位置使用多条路线吗?如果是,有人可以解释我该怎么做,或者任何教程?现在我只有1条路线.
我正在尝试迁移到 google admin sdk。我正在尝试使用 python 将成员添加到组(邮件列表)。我已经弄清楚如何创建组,但无法弄清楚如何添加成员。我已阅读此页面:https : //developers.google.com/admin-sdk/directory/v1/reference/members/insert但无法弄清楚如何将其映射到 python(我对 REST 或 python 几乎没有经验,我我正在努力学习)。
这就是我尝试这样做的方式:
import httplib2
from apiclient.discovery import build
from oauth2client.client import SignedJwtAssertionCredentials
keyFile = file(p12File, 'rb')
key = keyFile.read()
keyFile.close()
credentials = SignedJwtAssertionCredentials(serviceAccount,
key,
scope,
prn=superAdmin)
http = httplib2.Http()
httplib2.debuglevel = False #change this to True if you want to see the output
http = credentials.authorize(http=http)
directoryService = build(serviceName='admin', version='directory_v1', http=http)
# THIS DOES NOT WORK
groupinfo = {'email': 'wibble@XXX.co.uk'}
directoryService.groups().insert(groupKey='mygroup@XXX.co.uk', body=groupinfo).execute()
Run Code Online (Sandbox Code Playgroud)
当我运行时,我得到:
Traceback (most recent …Run Code Online (Sandbox Code Playgroud) 我正在使用谷歌路线来获取两点之间的主要路线,它是备选路线 (3),因此每个备选路线都包含步骤以及所有这些步骤的结果的概览折线,因此我想在地图中绘制这 3 条折线以查看主要路线和替代方案,你知道怎么做吗?
这是概览折线之一
"overview_polyline": {
"points": "uiyqBfb~zQgGwAgCtM}DfVpDrBeBbFqDjFmHfXkOzh@cKxNuGlW_BzSiJxZcBfHuS~NqK`Ia@lFgIpC{fAoDcW~BmEbBeqAmIaEoBgB{KB}J}OoJcBwAeHuAwDaBkCnCwKjLcNgBkIc@oDtD}EhG{GjAgVcDsN{Bm@|FaAvOiE|Va`@xw@}Jh]dPhcArEzQuIpXkMna@sDbPb@fGdDxE|O~E~ZzH`ThQtdA|jA|NfRxC~Jc@p[iEd`@WbSvKza@rTlf@~ArMfFtJrChOjQfM~JzX@~VnOn]g@jMcBdLkGzHg@|DyGfEcEjLgEvHaKoAgNiEoLsCoKUkUz@_CtBqI?eDhAeGeDsIRyK`IqIfIkPtEuUbNcLpOuPpZ]rHpHtQpLnOlEvIEpJfId[pShc@z@th@cLx@yNnGk`@rVsLfLm|@v|@_VxKgZ`XmR~VeH~^~@jIsAvLeD~LiCre@mGhP}Eda@D`YqBt[aIna@iI|Db@pENpDtAzCc@pG{@bFuQlGcLxGuUz@}PhBUhIcD`Eof@rMwUfEk^|Ck}@tFcMjDiP~GeN`RcF]}CxBmEc@{BvAoGdCsKpFmOgEuB\\eEjKjB~GwGvBiDsDgEyGwD`JeDTgCyGuCOcGvFmGzJeC_DwCa@WvM{@rC_CJuHoIiFEgBwC{HeJuCm@sAxAf@fFoBvBmDx@iNm@mCxD{DkAwMrDcJrF}IhSsDbB{D{AyY_CoK~AuP`@uPm@eKbC}Lq@eNsCeDeC_Jj@wIb@mEr@eHgBiGoKiGyJeDgI}CmHG{KiCyO}P}IgNkNaUoKkCkDYiB{Bg@sFwAaDeDsSwT}PY{KaEeIBqTfEiEeEgDkLyUyIkT}BoP{DyGiGwHiW{Is^kOiScLmTeIqGsPcTqD_FgMaDwNqMwOuVqHy\\yFkMmGwEaHeAqBmCr@aU_CiBoSpDyHBkH}Kc[kTq[mPyYiOyVyR_Sc\\{ZsRwfA{]wh@oPaNVyIiFeHKmE~AqAhEwNgDiNmFgL~H}Cs@oIxH{DRsFqG_FoA}GfEgP~MuFi@}Sh@yDdDgInBaGh@w[cCwH~AeGeFeLcUD_LkAiDwUaJuMXaQuGyBgB|LkLhL{JnPoGhIuQfACz@kEqCgBF}F~@qL{AaHa@qJCcHiAsBeH]{PiHeJoCu@{BxCwC[cFiVePaGt@}KoH_NyMyNiGyWwMeIgFiLmIod@lEoSaf@eIrF{@oG}C_@{B{CsEmAmDgCcAoL_AaFs@oCl@mD\\eMkHkFaJqFkEiPN}HrBvKdEzExA|FJJ"
},
Run Code Online (Sandbox Code Playgroud) 我正在创建一个Android应用程序,需要在X公里后找到同一路线上的坐标.
我有两个坐标x1,y1和x2,y2道路上.现在,我的要求是在同一条道路上找到x3,y33公里后的坐标(即x2,y2不在x1,y1&之间的坐标x2,y2).
怎么能实现这一目标?
android google-maps geolocation latitude-longitude google-directory-api
google-maps ×4
java ×3
android ×2
python ×2
client ×1
geolocation ×1
google-api ×1
google-apps ×1
oauth-2.0 ×1
python-2.7 ×1