Shotster
Shotster

Reputation: 3

How to get Google calendar's "Location" setting via Google Apps Script?

When creating a Google calendar or modifying its settings via the UI, there is a "Location" field. I'd like to get the value of that field via Google Apps Script (GAS).

Unfortunately, it appears to either be undocumented or not exposed through the GAS Calendar API. I've searched the net as well as SO, but I want to make sure I'm not overlooking something.

Please Note: I'm not referring to an event location, but rather the "Location" field of the calendar itself, which is entered via "Calendar settings" in the UI.

Upvotes: 0

Views: 1941

Answers (2)

Mr.Rebot
Mr.Rebot

Reputation: 6791

Try using the Advanced Calendar Service:

The advanced Calendar service allows you to use the public Google Calendar API in Apps Script. Much like Apps Script's built-in Calendar service, this API allows scripts to access and modify the user's Google Calendar, including additional calendars that the user is subscribed to. In most cases, the built-in service is easier to use, but this advanced service provides a few extra features, including setting the background color for individual events.

Then read the Calendars reference.

Resource representations:

{
  "kind": "calendar#calendar",
  "etag": etag,
  "id": string,
  "summary": string,
  "description": string,
  "location": string,
  "timeZone": string
}

Note:

location - Geographic location of the calendar as free-form text. Optional.

This mean that you can either get a location or not (if not set).

There are also Try this API for Calendars: insert and Calendars: get to see how Calendar - location works.

Hope this helps.

Upvotes: 1

mhawksey
mhawksey

Reputation: 2053

With the Calendar Service in Google Apps Script there are two methods for setting location. With the createEvent() method you can include location and other metadata in the options parameter:

// Creates an event for the moon landing and logs the ID.
var event = CalendarApp.getDefaultCalendar().createEvent('Apollo 11 Landing',
     new Date('July 20, 1969 20:00:00 UTC'),
     new Date('July 20, 1969 21:00:00 UTC'),
     {location: 'The Moon'});
Logger.log('Event ID: ' + event.getId());

Alternatively there is a setLocation() method for a CalendarEvent e.g.

// Creates an event for the moon landing and logs the ID.
var event = CalendarApp.getDefaultCalendar().createEvent('Apollo 11 Landing',
     new Date('July 20, 1969 20:00:00 UTC'),
     new Date('July 20, 1969 21:00:00 UTC'));
event.setLocation('The Moon');
Logger.log('Event ID: ' + event.getId());

Upvotes: 0

Related Questions