我已在Google电子表格脚本中尝试使用此代码,为我的Google Apps域用户添加另一封(外部)电子邮件:
function createExternalEmail() {
var userId = "sampleuser@mydomain.org";
var update = {
emails:
{
address: "sampleuser@homeemail.com",
type: "home",
customType: "",
primary: false
},
addresses:
{
type: "home",
customType: "",
streetAddress: "1600 Amphitheatre Parkway",
locality: "Mountain View",
region: "CA",
postalCode: "94043"
}
}
update = AdminDirectory.Users.update(update, userId);
var user = AdminDirectory.Users.get(userId);
Logger.log('User emails:\n %s', JSON.stringify(user.emails, null, 2));
Logger.log('User addresses:\n %s', JSON.stringify(user.addresses, null, 2));
}
但是Logger.log中没有返回更新的值。缺少什么?
答案 0 :(得分:1)
根据Admin SDK Reference,emails
和addresses
是列表(数组)。您已在更新中提供了对象。将它们用方括号括起来,使它们成为单元素数组。
尝试:
function createExternalEmail() {
var userId = "sampleuser@mydomain.org";
var update = {
emails:
[{
address: "sampleuser@homeemail.com",
type: "home",
customType: "",
primary: false
}],
addresses:
[{
type: "home",
customType: "",
streetAddress: "1600 Amphitheatre Parkway",
locality: "Mountain View",
region: "CA",
postalCode: "94043"
}]
}
update = AdminDirectory.Users.update(update, userId); // You should check your response!!!
var user = AdminDirectory.Users.get(userId);
Logger.log('User emails:\n %s', JSON.stringify(user.emails, null, 2));
Logger.log('User addresses:\n %s', JSON.stringify(user.addresses, null, 2));
}