-1

任何人都可以向我建议如何使用 2 个不同的 API 获取 google 组的内容

  1. 云身份 API
  2. 谷歌目录 API

我们需要获取 google 群组内容。

4

1 回答 1

0

好吧,这两个 API 都可以与 Google 群组进行交互,但是,它们之间存在细微差别,您可以在此处查看

我强烈建议使用Directory API,因为它有更好的文档,而且Cloud Identity API需要Cloud Identity FreeCloud Identity Premium帐户。但当然,它们中的任何一个都可以使用。


目录 API

对于Directory API,我建议您看一下Quickstart,因为在那里以您最喜欢的编程语言解释了有关 API 设置的所有内容。

关于如何处理组的文档在这里

当然,Apps Script是获取该信息的最直接的工具,因为它可以在几行中实现(并添加AdminDirectory服务):

function myFunction() {

  var groupList = AdminDirectory.Groups.list({customer:"my_customer"})["groups"];
  
  for (var i = 0; i < groupList.length; i++){ 
    console.log(groupList[i].name+": " + groupList[i].description);
  }
}


云身份 API

关于Cloud Identity API,您需要遵循此设置

然后,可以在此处找到有关组的文档。

例如,以下是如何在Apps Script中完成的:

function myFunction() {
  var customerId = AdminDirectory.Users.get(Session.getEffectiveUser().getEmail()).customerId;

  var url = "https://cloudidentity.googleapis.com/v1beta1/groups?parent=customers/"+customerId;
  var params = {
    method: "get",
    headers: {"Authorization": "Bearer " + ScriptApp.getOAuthToken()},
  };
  
    var groups = JSON.parse(UrlFetchApp.fetch(url,params).getContentText()).groups;
    
    for(var i = 0; i< groups.length;i++){
      console.log(groups[i].displayName); 
    }
}

为此,您还需要在 appscript.json清单文件中附加以下行。您可以通过转到项目设置->在编辑器中显示“appsscript.json”清单文件来打开它:

"oauthScopes": ["https://www.googleapis.com/auth/script.external_request",
 "https://www.googleapis.com/auth/cloud-identity.groups"]
于 2022-01-19T13:14:40.430 回答