Dave Owens
Dave Owens

Reputation: 450

How can I get a resource's schedule from google calendar?

We use google calendar to schedule our meetings. We have set up each meeting room as a "resource" so that you can see availability and book a room by adding the resource to your meeting.

What I'd like to do is display today's schedule in for each room in each room.

I don't see a way to do that simply using google calendar, so I tried to do it programmatically with javascript through Google's API. I could get the current user's schedule (see code below), but, not a resource's schedule.

Does anyone know if there's a way to get a single resource's schedule either visually as a day's schedule or programmatically so I can create a day's schedule?

  function listUpcomingEvents() {
    var request = gapi.client.calendar.events.list({
      'calendarId': 'primary',
      'timeMin': (new Date()).toISOString(),
      'showDeleted': false,
      'singleEvents': true,
      'maxResults': 10,
      'orderBy': 'startTime'
    });

    request.execute(function(resp) {
      var events = resp.items;
      appendPre('Upcoming events:');

      if (events.length > 0) {
        for (i = 0; i < events.length; i++) {
          var event = events[i];
          var when = event.start.dateTime;
          if (!when) {
            when = event.start.date;
          }
          appendPre(event.summary + ' (' + when + ')');
          var attendees = event.attendees;
          if (attendees.length > 0) {
            for (i=0; i<attendees.length; i++) {
              var attendee = attendees[i];
              if (attendee.resource) {
                appendPre('   RESOURCE: ' + attendee.displayName + ' (' + attendee.json + ')');
              } else {
                appendPre('   ' + attendee.displayName);
              }
            }
          }
        }
      } else {
        appendPre('No upcoming events found.');
      }

    });
  }

Upvotes: 2

Views: 2464

Answers (2)

Mogsdad
Mogsdad

Reputation: 45720

I don't see a way to do that simply using google calendar, ...

Using the same ID described in luc's answer, you can view a resource calendar in your browser.

A link would look like this, for example:

https://www.google.com/calendar/[email protected]&mode=WEEK&wkst=1&showCalendars=0

Note that you can control the view via URL parameters, so easy to keep a shortcut in a browser.

screenshot

To view resource calendars within Google Calendar app:

  1. At the right of "Other Calendars", open the menu and select "Browse Interesting Calendars".
  2. On the "Interesting Calendars" page, select "More", then "Resources for domain".
  3. Find the resource you are interested in, and Preview the calendar.

To obtain the calendar ID, click on the "subscribe" button (lower right of preview), which will open a new window with a confirmation dialog. While this is visible, the calendar's ID can be copied from the URL bar, e.g. https://www.google.com/calendar/[email protected]&blah...

Upvotes: 1

luc
luc

Reputation: 3782

You will need to find out the ID of your resource (it's an email address - resourceEmail - that you can for example see through the resource API https://developers.google.com/admin-sdk/calendar-resource/). Once you have that, if the logged in account has read access to that resource's calendar, you can just replace calendarId in your query with the resourceEmail.

Upvotes: 2

Related Questions