2014-04-25 42 views
0

即時通訊設法訪問Google Apps網域中的日曆資源數據。從Google Apps腳本中的API中獲取數據,如何操作?

我有這樣的:

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); 

} 

但我需要授權。

「請求失敗https://apps-apis.google.com/a/feeds/calendar/resource/2.0/example.com/返回所需的代碼401授權」

是否有人知道我是如何授權?我試圖添加先進的服務和日曆API,但沒有奏效。

回答

2

爲什麼不在Google Apps腳本中使用Calendar Service。它允許您與日曆對象和事件交互,而不用擔心oAuth。

e.g獲取活動日曆

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()); 
    } 
} 

欲瞭解更多詳情,可參考下面的資源。

相關問題