user3432918
user3432918

Reputation: 131

Get data from API in Google Apps Script, how to?

im trying to access the calendar resources data in the Google Apps domain.

I have this:

function myFunction() {

  var url = 'https://apps-apis.google.com/a/feeds/calendar/resource/2.0/example.com/';

  var response = UrlFetchApp.fetch(url);
Logger.log(response);

}

But i need to authorize.

"Request failed for https://apps-apis.google.com/a/feeds/calendar/resource/2.0/example.com/ returned code 401. Authorization required "

Does someone know how i Authorize? I tried to add the advances services and Calendar API, but didn't work.

Upvotes: 0

Views: 218

Answers (1)

Waqar Ahmad
Waqar Ahmad

Reputation: 3732

Why don't you use Calendar Service in Google Apps Script. It allows you to interact with Calendar Objects and Events without worrying for oAuth.

e.g to Fetch Events in Calendar

function fetchEVents() {
  var d1 = new Date("4/26/2013");
  var d2 = new Date("4/26/2014");
  var events = CalendarApp.openByName("myCalendarName").getEvents(d1, d2);

  if (events.length > 0) { // Log the time of first event
    Logger.log(events[0].getStartTime() + " : " + events[0].getEndTime());
  }
}

For more details, you may refer to the following resources.

Upvotes: 2

Related Questions