如何在Google应用脚本中获取特定用户的组织名称?

时间:2016-09-29 11:10:57

标签: google-apps-script google-admin-sdk admin-sdk

当我执行以下代码时

foo

我得到了如下输出 -

CN = AdminDirectory.Users.get(user).organizations;

但我想单独打印每个项目,如下所示

customType =

名= OPOP

description =软件工程师

标题= SWE

我该怎么做?

提前致谢

1 个答案:

答案 0 :(得分:0)

正如Admin SDK Directory Service中所述,开发人员可以在Apps脚本中使用Admin SDK的目录API。此API为Google Apps域(包括经销商)管理员提供了管理其域中的设备,组,用户和其他实体的功能。

使用目录API,您可以使用GET请求retrieve an organization unit并包含Authorize requests中所述的授权。 orgUnitPath查询字符串是此组织单位的完整路径。

还在文档中讨论:

  

如果您是管理员检索组织单位,请使用my_customer

GET https://www.googleapis.com/admin/directory/v1/customer/my_customer/orgunits/orgUnitPath
  

如果您是转售商检索转售客户的单位部门,请使用customerId。要使customerId使用Retrieve a user操作。

GET https://www.googleapis.com/admin/directory/v1/customer/customerId/orgunits/orgUnitPath

如果您想单独打印,这里是一个示例请求,其中检索“一线销售”组织单位。请注意请求的URI中的“frontline + sales”HTTP编码:

GET https://www.googleapis.com/admin/directory/v1/customer/my_customer/orgunits/corp/sales/frontline+sales

成功的响应返回HTTP 200状态代码。与状态代码一起,响应返回组织单位的设置:

{
    "kind": "directory#orgUnit",
    "name": "frontline sales",
    "description": "The frontline sales team",
    "orgUnitPath": "/corp/sales/frontline sales",
    "parentOrgUnitPath": "/corp/sales",
    "blockInheritance": false
}

希望有所帮助!