简体   繁体   English

如何使用目录 API 或 Cloud Identity API 获取 Google 群组内容

[英]how to get Google groups contents by using directory API or Cloud Identity API

Can anyone please suggest to me how to get the content of google groups by using 2 different API任何人都可以向我建议如何使用 2 个不同的 API 获取 google 组的内容

  1. Cloud identity API云身份 API
  2. google directory API谷歌目录 API

We need to get the google group content.我们需要获取 google 群组内容。

Well, both APIs can interact with Google groups, however, there are subtle differences between them than you can check here .好吧,这两个 API 都可以与 Google 群组进行交互,但是,它们之间存在细微的差异,您可以在此处查看

I would strongly recommend using the Directory API as it has better documentation and as the Cloud Identity API requires either a Cloud Identity Free or a Cloud Identity Premium account.我强烈建议使用目录 API ,因为它有更好的文档,而且Cloud Identity API需要Cloud Identity 免费版或Cloud Identity 高级版帐户。 But of course, either of them can be used.但当然,它们中的任何一个都可以使用。


Directory API目录 API

For Directory API I would recommend taking a look at the Quickstart , as everything regarding the API's setup in your favorite programming language is explained there.对于目录 API ,我建议您查看快速入门,因为此处解释了有关使用您最喜欢的编程语言设置 API 的所有内容。

The documentation on how to deal with groups is here .关于如何处理组的文档在这里

Of course, Apps Script is the most straightforward tool to fetch that information, as it can be achieved in a few lines (and adding the AdminDirectory service):当然, 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);
  }
}


Cloud Identity API云身份 API

Regarding Cloud Identity API , you will need to follow this setup .关于Cloud Identity API ,您需要遵循此设置

Then, the documentation regarding groups can be found here .然后,可以在此处找到有关组的文档。

As an example, here is how it could be done in Apps Script :例如,以下是如何在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); 
    }
}

For that you would also need to append the following line in the appscript.json manifest file.为此,您还需要 append appscript.json清单文件中的以下行。 You can open it by going to Project Settings -> Show "appsscript.json" manifest file in editor :您可以通过转到项目设置->在编辑器中显示“appsscript.json”清单文件来打开它:

"oauthScopes": ["https://www.googleapis.com/auth/script.external_request",
 "https://www.googleapis.com/auth/cloud-identity.groups"]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM