使用Google Apps脚本将成员添加到Google网上论坛 [英] Add member to google groups using Google Apps Script

查看:68
本文介绍了使用Google Apps脚本将成员添加到Google网上论坛的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种方法,可以通过google apps脚本将用户添加到我自己的google-group中(至少向他发送邀请).

I am looking for a method to add an user to my own google-group (at least to send him an invitation) from google apps script.

代码段是:

  var options = {  "method"  : "POST",
        "payload" : {"email": email,"role": "MEMBER"},   
        "muteHttpExceptions": true};

  var result = UrlFetchApp.fetch("https://www.googleapis.com/admin/directory/v1/groups/" + respGroup+"/members?key=" + key, options);

但是答案是:

{
  "error": {
    "errors": [{
      "domain": "global",
      "reason": "required",
      "message": "Login Required",
      "locationType": "header",
      "location": "Authorization"
    }],
  "code": 401,
  "message": "Login Required"
  }
}

我知道问题可能出在OAuth身份验证上,但是我该怎么办呢?

I understood that the problem could be the OAuth authentication, but how do I do it?

推荐答案

您可以使用AdminDirectory API(应在资源"标签中激活的扩展Google服务)轻松完成此操作

You can do that easily using the AdminDirectory API (extended Google services that should be activated in the ressource tab)

代码就是这样简单:

function addGroupMember(userEmail,groupEmail) {
  var member = {
    email: userEmail,
    role: "MEMBER"
  };
  member = AdminDirectory.Members.insert(member, groupEmail);
  Logger.log("User %s added as a member of group %s.", userEmail, groupEmail);
}

这篇关于使用Google Apps脚本将成员添加到Google网上论坛的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆