0

Calendar.getName() function returns calendar owner's email address.This behavior is the same as Calendar.getId(). I want to get the calendar owner's display name. What function should I use?

This is for Google Apps Script. https://developers.google.com/apps-script/reference/calendar/calendar

Logger.log('calendar.getName() : ' + calendar.getName());

I expect the output of Mizuki Kojima[IT department], but the actual output is mkojima51@example.co.jp.

theduck
  • 2,589
  • 13
  • 17
  • 23

1 Answers1

0

The Calendar.getName() function is working as expected: It returns the display name of the calendar, and in case the calendar is a primary calendar of a user and its name has never been edited, it will be the same as the obtained via Calendar.getId() (the user's e-mail address).

If what you want is to get the user's name of the calendar owner, you only have one option. Also, this will be assuming that you are using a G Suite account, and that both the one executing the script and the calendar owner are part of the same domain:

  1. Get the calendar's id. If it is an e-mail (there are many ways you can do this verification), that means that the owner of it has an account with that same e-mail.
  2. Get the user's profile using the G Suite Admin SDK. For that, you will make a call to Users.get(). Afterwards, you can get the name and surname from the profile object returned.
carlesgg97
  • 4,184
  • 1
  • 8
  • 24