从Google API脚本-Google Admin Directory中的用户个人资料中检索自定义属性 [英] Retrieve custom attribute from user profile in Google API Scripts- Google Admin Directory
问题描述
这与G Suite用户有关.以下内容在使用Google Admin SDK的Google Admin目录中有效.它检索电子邮件地址和用户的全名.
This is about G suite users.The following works in Google Admin Directory using Google Admin SDK. It retrieves email address and full name of user.
var myemail = Session.getActiveUser().getEmail();
var mycontact = AdminDirectory.Users.get(myemail);
var myname = mycontact.name.fullName;
用户个人资料中有一个名为部门"的自定义属性.以下内容不检索任何内容.它抛出空值
There is a custom attribute in user profile named "Department". The following does NOT retrieve anything. It throws null
var mydept = mycontact.Department;
如何从G Suite的用户个人资料中检索自定义属性?
How can one retrieve custom attribute from user profile in G suite?
推荐答案
根据.
According to Directory Api - Users: get you need to set the projection
to "custom"
.
投影-要为此用户获取哪些字段子集.
projection - What subset of fields to fetch for this user.
可接受的值为:
基本":不为用户包括任何自定义字段.(默认)
"basic": Do not include any custom fields for the user. (default)
自定义":包括customFieldMask中请求的模式中的自定义字段.
"custom": Include custom fields from schemas requested in customFieldMask.
完整":包括与此用户关联的所有字段.
"full": Include all fields associated with this user.
然后,您应为模式定义自定义数据
Then you should define a Schema for the custom data
customFieldMask (字符串)以逗号分隔的架构名称列表.这些架构中的所有字段均已获取.仅应在projection = custom时设置.
customFieldMask (string) A comma-separated list of schema names. All fields from these schemas are fetched. This should only be set when projection=custom.
类似这样:
var mycontact = AdminDirectory.Users.get({
"userKey": myemail,
"projection": "full",
"customFieldMask": "Define Schema Here"
});
然后您可以 Logger.log(mycontact);
来查看如何访问返回的自定义字段
You can then Logger.log(mycontact);
to see how to access the returned custom fields
这篇关于从Google API脚本-Google Admin Directory中的用户个人资料中检索自定义属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!