域中的每个用户都会启动一个简单的脚本,我们为leave授权运行该脚本,但是我们希望欢迎消息是"Hi First Name“,但是该脚本似乎不能从标准用户的getActiveUser()中获取getGivenName()。
有什么办法吗?
发布于 2013-03-26 10:44:38
如注释和Documentation中所述,只有域管理员可以访问UserManager服务。
这里有一个替代方案。域用户可能会在自己的联系人中找到自己,那么如何尽最大努力在那里找到自己?
/**
* Get current user's name, by accessing their contacts.
*
* @returns {String} First name (GivenName) if available,
* else FullName, or login ID (userName)
* if record not found in contacts.
*/
function getOwnName(){
var email = Session.getEffectiveUser().getEmail();
var self = ContactsApp.getContact(email);
// If user has themselves in their contacts, return their name
if (self) {
// Prefer given name, if that's available
var name = self.getGivenName();
// But we will settle for the full name
if (!name) name = self.getFullName();
return name;
}
// If they don't have themselves in Contacts, return the bald userName.
else {
var userName = Session.getEffectiveUser().getUsername();
return userName;
}
}
发布于 2017-03-20 10:03:53
在应用程序脚本中,我可以使用关于REST API:https://developers.google.com/drive/v2/reference/about/get获取此信息
var aboutData = DriveApp.About.get();
var userEmail = aboutData["user"]["emailAddress"];
var userDisplayName = aboutData["user"]["displayName"];
发布于 2013-02-22 12:44:57
您可以获取用户名,但首先必须使用provisioning api创建域用户。您可以通过登录到您的管理员帐户来启用API,然后选择域设置和用户设置选项卡以选中启用配给API的复选框。阅读有关它的更多信息here
然后,您可以使用
user = user.getgivenName()
https://stackoverflow.com/questions/15016628
复制相似问题