Yaa*_*ler 3 google-api google-groups google-apps-script
我正在尝试使用Google Apps脚本将用户添加到Google网上论坛。
这是我尝试过的代码:
// Adds a user to a Google Group
function addUsertoGroup(userEmail) {
var userEmail = 'Name@gmail.com'
var groupId = "group-name@googlegroups.com";
var group = GroupsApp.getGroupByEmail(groupId);
// If email is already in group
try { var hasMember = group.hasUser(userEmail);}
catch(e){Logger.log(userEmail+" is already in the group"); return}
var newMember = {email: userEmail, role: "MEMBER"};
// This is the line which is throwing an error
AdminDirectory.Members.insert(newMember, groupId);
Run Code Online (Sandbox Code Playgroud)
运行时,我收到一个错误:
对directory.groups.get的API调用失败,并出现以下错误:未找到域。
任何帮助,将不胜感激。
Clarification:
AdminDirectory function (or to have the ability to add users to a group via Apps Script.gmail or any other non-same domain users based on the group setting you configure via https://groups.google.comSolution:
I have a G Suite account via script.gs and I tested the code that you've shared - its perfect :) Except for the following that you need to enable, from a G Suite account.
Navigate to Resources > Advanced Google Services... and enable Admin Directory API
That's it. I created the group, enabled all settings, made the group accessible to everyone and it worked like a charm.
Let me know if you require any further clarification or assist as well.
Edit notes:
So, this is also what I had to follow to ensure everyone (even folks outside the domain could be added as users), as documented on Set Groups for Business sharing options. When you go to Groups for Business and navigate through the settings, you'd get to enable the following option that's critical -
Obviously, you're free to tweak all the other settings, as required.
| 归档时间: |
|
| 查看次数: |
169 次 |
| 最近记录: |