问题
I have a Google Apps Script which has all the permissions it needs, with the Group Settings API on and working, but does not change certain things. There are no errors given, but the only thing that changes is the name, and the rest does nothing. This is the script:
function modgroup() {
var groupKey = 'finaltest@school.edu.mx';
var resource = {
name: "finalfour",
whoCanContactOwner: "ALL_MEMBERS_CAN_CONTACT",
whoCanJoin: "INVITED_CAN_JOIN",
whoCanViewMembership: "ALL_MEMBERS_CAN_VIEW",
whoCanViewGroup: "ALL_MEMBERS_CAN_VIEW",
whoCanInvite: "ALL_MANAGERS_CAN_INVITE",
whoCanAdd: "ALL_MANAGERS_CAN_ADD",
allowExternalMembers: false,
whoCanPostMessage: "ALL_MEMBERS_CAN_POST",
allowWebPosting: false
}
AdminDirectory.Groups.update(resource, groupKey);
}
回答1:
Ok, after a bit of investigation and experimentation, I found that there was another API and another format that had to be used so that it will work. You need to activate the Groups Settings API (not the Admin Directory API) and you can see the documentation here.
The format is the following:
function editGroup(){
var groupId = 'finaltest@school.edu.mx';
var group = AdminGroupsSettings.newGroups();
group.name = 'NAME';
group.description = 'DESCRIPTION';
group.whoCanAdd = 'NONE_CAN_ADD';
group.whoCanJoin = 'INVITED_CAN_JOIN';
group.whoCanViewMembership = 'ALL_MEMBERS_CAN_VIEW';
group.whoCanViewGroup = 'ALL_MEMBERS_CAN_VIEW';
group.whoCanInvite = 'ALL_MANAGERS_CAN_INVITE';
group.allowExternalMembers = false;
group.whoCanPostMessage = 'ALL_MEMBERS_CAN_POST';
group.allowWebPosting = true;
group.showInGroupDirectory = false;
group.allowGoogleCommunication = false;
group.membersCanPostAsTheGroup = false;
group.includeInGlobalAddressList = false;
group.whoCanLeaveGroup = 'NONE_CAN_LEAVE';
AdminGroupsSettings.Groups.patch(group, groupId);
}
来源:https://stackoverflow.com/questions/51461276/how-to-update-google-group-settings-with-google-apps-script