[英]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.