Getting user's name from email in Google Apps Domain?

廉价感情. 提交于 2019-12-25 04:15:37

问题


I have an email from a Google Apps domain. I can see a list of all users in a domain by going into google apps' Contacts page, under 'Domain'.

If I wanted to get their full name from that email, how would I go about doing so? I've tried using ContactsApp to no avail. I also can't use UserManager in the domain tools as I don't have access to the admin tools.

Any ideas on how I could go about this?


回答1:


Your question is similar to Google Script How do I getGivenName() of getActiveUser(), although in that case an admin was trying to create a service that a script run by members of the domain could use to get their own full names.

It's this answer that might help. As a domain user, you can get the full name of people in your own contact list. Add enough people (or the right people), and your success rate will be pretty high.

Here's a modified version of that script.

/**
 * Get a user's name, by accessing contacts.
 *
 * @returns {String} FullName, or UserID
 *                   if record not found in contacts.
 */
function getUserName(email){
  var user = ContactsApp.getContact(email);

  // If user in contacts, return their name
  if (user) {
    // Get full name
    var name = user.getFullName();
  }
  if (!name) {
    // If not in Contacts, return the bald userID.
    name = email.split('@')[0];
  }
  return name;
}



回答2:


Ask the admins to get yourself granted read only access to the provisioning API for users. That and the GAL feed are covered in the answers to this question: How can I get read-only access to the Google Apps Profiles API?



来源:https://stackoverflow.com/questions/16008421/getting-users-name-from-email-in-google-apps-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!