简体   繁体   English

使用 App Script 和 Admin SDK 设置 G Suite 用户属性

[英]Setting G Suite user properties with App Script and the Admin SDK

I'm trying to set a user's OU from an App Script inside App Maker.我正在尝试从 App Maker 中的 App Script 设置用户的 OU。 ( user is a variable with an email address) user是一个带有电子邮件地址的变量)

function getUser(user) {
  var x = AdminDirectory.Users.update(
    {
      orgUnitPath: "/",
      userKey: user,
    });
  console.log("function ran");
}

This code errors with:此代码错误:

Exception: Invalid number of arguments provided. Expected 2-3 only at getUser (ServerScripts:107)
Invalid number of arguments provided. Expected 2-3 only
at getUser (ServerScripts:107)
at getUser (ClientHandoff:21:21)
at TestMoveOU.Panel1.Button1.onClick:1:1

What am I doing wrong here?我在这里做错了什么? Looking at the docs , you only need to provide the properties you're changing.查看docs ,您只需要提供您正在更改的属性。

The Apps Script documentation says the following: Apps 脚本文档说明如下:

For detailed information on this service, see the reference documentation for the Admin SDK Directory API.有关此服务的详细信息,请参阅 Admin SDK Directory API 的参考文档。 Like all advanced services in Apps Script, the Admin SDK Directory service uses the same objects, methods, and parameters as the public API.与 Apps Script 中的所有高级服务一样,Admin SDK Directory 服务使用与公共 API 相同的对象、方法和参数。

Therefore, we need to consult the documentation to get clarification on how to achieve this.因此,我们需要查阅文档以了解如何实现这一点。

The method requires at least two parameters: that means that the the first parameter is a user object resource and the second parameter is the email address of the user: AdminDirectory.Users.update(resource, userKey) .该方法至少需要两个参数:这意味着第一个参数是用户对象资源,第二个参数是用户的电子邮件地址: AdminDirectory.Users.update(resource, userKey) So you need to do this:所以你需要这样做:

function getUser(user) {
    var userResource = {
        orgUnitPath: "/"
    };
    var updated = AdminDirectory.Users.update(userResource, user);
    console.log(updated.primaryEmail);
}

So why do you need to specify the user email in the method when it is already being specified in the userResource object?那么,既然已经在userResource对象中指定了用户电子邮件,为什么还需要在方法中指定它呢? Well, the email address in the userResource object would be the new value, in case you want to change the email address.好吧,如果您想更改电子邮件地址,则userResource对象中的电子邮件地址将是新值。

PS Perhaps you might wanna change the name of the function to something that is more of a match; PS 也许您可能想将函数的名称更改为更匹配的名称; updateUser() perhaps? updateUser()也许? I hope this helps!我希望这有帮助!

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

相关问题 从G Suite管理员SDK删除用户帐户的脚本 - Script to delete a user account from G Suite Admin SDK G-Suite 用户访问 G-Suite 可信应用脚本时,如何避免脚本授权提示? - How to avoid script authorization prompt when G-Suite user is accessing G-Suite trusted app script? 在G-suite Admin SDK中获取所有已暂停用户的详细信息 - Fetch the details of all suspended users in G-suite Admin SDK 使用 Google Admin SDK 中的 google app 脚本自动创建用户 - Automate user creation using google app script in Google Admin SDK 将 Google Script Addon 发布到 G Suite Marketplace SDK - Publishing Google Script Addon to G Suite Marketplace SDK 是否可以将 Google Apps Script Web App 发布到 G Suite Marketplace? - Is it possible to publish a Google Apps Script Web App to G Suite Marketplace? 使用 Google Apps 脚本从 G Suite 管理控制台中删除 web 应用程序 - Remove the web apps from the G Suite Admin Console by using Google Apps Script 授权非管理员用户在 Google Apps 脚本中运行 Admin SDK - Authorizing a non admin user to run Admin SDK in Google Apps Script G Suite Marketplace SDK:无法保存表单 - G Suite Marketplace SDK: The form cannot be saved 使用 Google App Script 在 G 套件共享驱动器中创建 Google 文档快捷方式 - Creating a Google Document shortcut in a G suite shared drive using Google App Script
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM