Reputation: 19
Can anyone please suggest to me how to get the content of google groups by using 2 different API
We need to get the google group content.
Upvotes: 0
Views: 877
Reputation: 648
Well, both APIs can interact with Google groups, however, there are subtle differences between them than you can check here.
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. But of course, either of them can be used.
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.
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):
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);
}
}
Regarding Cloud Identity API, you will need to follow this setup.
Then, the documentation regarding groups can be found here.
As an example, here is how it could be done in 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. You can open it by going to Project Settings -> Show "appsscript.json" manifest file in editor:
"oauthScopes": ["https://www.googleapis.com/auth/script.external_request",
"https://www.googleapis.com/auth/cloud-identity.groups"]
Upvotes: 1