首页 > 解决方案 > 无法在 Google Directory API 中获取根 Orgunit

问题描述

我正在尝试获取有关根组织单位的信息。我尝试使用orgunits.listorgunits.get方法,但都失败了。

   const service = google.admin({version: 'directory_v1', auth});
service.orgunits.list({
    customerId: 'my_customer',
    orgUnitPath: '/',
    type: 'all' 
}, (err, res) => {
    if (err) return console.error('The API returned an error:', err.message);
    const data = res.data;
    console.log(data);
});

orgunits.list只返回两个值(如果我没有任何子单位):

{kind: "admin#directory#orgUnits", etag: "..."}

orgunits.get返回未找到错误:

   service.orgunits.get({
    customerId: 'my_customer',
    orgUnitPath: '/'
    // orgUnitPath: 'id:...'
}, (err, res) => {
    if (err) return console.error('The API returned an error:', err.message);
    const data = res.data;
    console.log(data);   
});

只有当我添加一个子单位然后运行​​orgunits.list然后按照此处的建议在子单位中查找父单位 ID时,我才成功获取有关根组织单位的信息。

所以问题是如果没有子单元,如何获取根组织单元或组织单元 ID?

标签: node.jsgoogle-apigoogle-directory-api

解决方案


我不确定您想要做什么,但在 Google 上获取根“/”组织单位会检索所有域。


推荐阅读