Google Calendar Event List

Accessing to Google Calendar and retrieves a list of events (schedules) registered during the specified time period. In combination with Workflow, it will be possible to get schedule of next week collectively, and notify (announce) them by email.

    A. Set OAuth2 Config Name (at [OAuth 2.0 Setting])Single-line inputRequired
    B. Set CalendarID (e.g japanese__ja@holiday.calendar.google.com)Single-line inputRequired
    C. Select DATE DATA for Start DateData selectDateRequired
    D. Select DATE DATA for End DateData selectDateRequired
    E. Set Timezone of Date Data (e.g -07:00)Single-line inputRequired
    F. Select STRING DATA for Events List (update)Data selectString(multiple line)Required
    X. Select STRING DATA for Access Log (update)Data selectString(multiple line)
    -variable namevariable label
    Aconf_OAuth2Set OAuth2 Config Name (at [OAuth 2.0 Setting])
    Bconf_CalendarIdSet CalendarID (e.g japanese__ja@holiday.calendar.google.com)
    Cconf_DataIdCSelect DATE DATA for Start Date
    Dconf_DataIdDSelect DATE DATA for End Date
    Econf_TimezoneSet Timezone of Date Data (e.g -07:00)
    Fconf_DataIdFSelect STRING DATA for Events List (update)
    Xconf_DataIdXSelect STRING DATA for Access Log (update)
    // Google Calendar Events List via Calendar API v3 (ver. 20170801)
    // (c) 2017, Questetra, Inc. (the MIT License)
    
    //// == 工程コンフィグの参照 / Config Retrieving ==
    var oauth2  = configs.get( "conf_OAuth2" ) + "";
    var calendarId  = configs.get( "conf_CalendarId" ) + "";
    var timezone    = configs.get( "conf_Timezone" ) + "";
    
    var dataIdC = configs.get( "conf_DataIdC" ); // returns key
    var dataIdD = configs.get( "conf_DataIdD" ); // returns key
    var dataIdF = configs.get( "conf_DataIdF" ); // returns key
    var dataIdX = configs.get( "conf_DataIdX" ); // returns key
    
    //// == ワークフローデータの参照 / Data Retrieving ==
    var startDate = data.get( dataIdC ) + ""; // "YYYY-MM-DD"
    var endDate   = data.get( dataIdD ) + ""; // "YYYY-MM-DD"
    
    //// == 演算 / Calculating ==
    // Set API Request
    var apiRequest = httpClient.begin();
    apiRequest.queryParam( "calendarId", calendarId );
    apiRequest.queryParam( "orderBy", "startTime" );
    apiRequest.queryParam( "singleEvents", "true" );
    apiRequest.queryParam( "timeMax", endDate + "T23:59:59" + timezone ); // for request
    apiRequest.queryParam( "timeMin", startDate + "T00:00:00" + timezone );
    apiRequest.queryParam( "timeZone", timezone ); // Time zone for response
    
    // Set OAuth2 Access Token
    var token = httpClient.getOAuth2Token( oauth2 );
    apiRequest.bearer( token );
    
    // API Access
    var accessLog = "";
    var uri = "https://www.googleapis.com/calendar/v3/calendars/calendarId/events";
    var response = apiRequest.get( uri );
    var statusCode = response.getStatusCode() + "";
    accessLog += "---GET request--- " + statusCode + "\n";
    accessLog += response.getResponseAsString() + "\n";
    
    // Retreive Response-JSON Properties
    var calendarEventsStr = "";
    if( statusCode == "200" ){
      var responseObj = JSON.parse( response.getResponseAsString() );
      for( var i = 0; i < responseObj.items.length; i++ ){
        if( "date" in responseObj.items[i].start ){
          // "date": "2017-07-24"
          calendarEventsStr += responseObj.items[i].start.date;
          calendarEventsStr += "\t(--:--):\t";
          calendarEventsStr += responseObj.items[i].summary; // 
        }else if( "dateTime" in responseObj.items[i].start ){
          // "dateTime": "2017-07-24T12:00:00+09:00"
          calendarEventsStr += responseObj.items[i].start.dateTime.substring(0,10);
          calendarEventsStr += "\t(" + responseObj.items[i].start.dateTime.substring(11,16) + "):\t";
          calendarEventsStr += responseObj.items[i].summary; // 
        }
        calendarEventsStr += "\n";
      }
    }
    
    //// == ワークフローデータへの代入 / Data Updating ==
    retVal.put( dataIdF, calendarEventsStr );
    if( dataIdX !== "" ){
      retVal.put( dataIdX, accessLog );
    }
    
    //retVal.put( "q_debugLog", debugLog );
    

    • B’: Google Calendar ID* stored in the Data Item selected at config B
    • C’: Start Date stored in the Data Item selected at config C
    • D’: End Date stored in the Data Item selected at config D
    • Event which has been registered in Google Calendar B’ scheduled in the period from C’ to D’ (E’, the time difference with UTC) will be stored in the data item selected at config F
    • The communication log will be stored in the Data Item selected at X
    • * Refers to the following page for Calendar ID
      • [Calendar Settings] > [Calendar Address]
    • You need to register Project at Google API Manager beforehand (Scope: “https://www.googleapis.com/auth/calendar”)
    • The Start Date C ‘ and the End Date D’ are specified in UTC with the time zone entered in E