Android™ Google Calendar: Get Instances of a Recurring Event

Back to Index

Returns instances of the specified recurring event.
This example gets instances for an event from the calendar having the ID = "support@chilkatcloud.com", where the event ID equals "6li3bfqqq65edprt4ms6vdld2j"

Documentation: https://developers.google.com/google-apps/calendar/v3/reference/events/instances


// Important: Don't forget to include the call to System.loadLibrary
// as shown at the bottom of this code sample.
package com.test;

import android.app.Activity;
import com.chilkatsoft.*;

import android.widget.TextView;
import android.os.Bundle;

public class SimpleActivity extends Activity {

  private static final String TAG = "Chilkat";

  // Called when the activity is first created.
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    CkRest rest = new CkRest();
    boolean success;

    //   Provide a previously obtained OAuth2 access token.
    CkOAuth2 oauth2 = new CkOAuth2();
    oauth2.put_AccessToken("OAUTH2_ACCESS_TOKEN");
    rest.SetAuthOAuth2(oauth2);

    success = rest.Connect("www.googleapis.com",443,true,true);
    if (success != true) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    CkStringBuilder sbJson = new CkStringBuilder();
    success = rest.FullRequestNoBodySb("GET","/calendar/v3/calendars/support@chilkatcloud.com/events/6li3bfqqq65edprt4ms6vdld2j/instances",sbJson);
    if (success != true) {
        Log.i(TAG, rest.lastErrorText());
        return;
        }

    if (rest.get_ResponseStatusCode() != 200) {
        Log.i(TAG, "Received error response code: " + String.valueOf(rest.get_ResponseStatusCode()));
        Log.i(TAG, "Response body:");
        Log.i(TAG, sbJson.getAsString());
        return;
        }

    CkJsonObject json = new CkJsonObject();
    json.LoadSb(sbJson);

    //  The following code parses the JSON response.
    //  A sample JSON response is shown below the sample code.
    String kind;
    String etag;
    String summary;
    String updated;
    String timeZone;
    String accessRole;
    String nextSyncToken;
    int i;
    int count_i;
    String method;
    int minutes;
    String id;
    String status;
    String htmlLink;
    String created;
    String description;
    String location;
    String creatorEmail;
    boolean creatorSelf;
    String organizerEmail;
    boolean organizerSelf;
    String startDateTime;
    String startTimeZone;
    String endDateTime;
    String endTimeZone;
    String recurringEventId;
    String originalStartTimeDateTime;
    String originalStartTimeTimeZone;
    String iCalUID;
    int sequence;
    String hangoutLink;
    boolean remindersUseDefault;
    int j;
    int count_j;

    kind = json.stringOf("kind");
    etag = json.stringOf("etag");
    summary = json.stringOf("summary");
    updated = json.stringOf("updated");
    timeZone = json.stringOf("timeZone");
    accessRole = json.stringOf("accessRole");
    nextSyncToken = json.stringOf("nextSyncToken");
    i = 0;
    count_i = json.SizeOfArray("defaultReminders");
    while (i < count_i) {
        json.put_I(i);
        method = json.stringOf("defaultReminders[i].method");
        minutes = json.IntOf("defaultReminders[i].minutes");
        i = i + 1;
        }

    i = 0;
    count_i = json.SizeOfArray("items");
    while (i < count_i) {
        json.put_I(i);
        kind = json.stringOf("items[i].kind");
        etag = json.stringOf("items[i].etag");
        id = json.stringOf("items[i].id");
        status = json.stringOf("items[i].status");
        htmlLink = json.stringOf("items[i].htmlLink");
        created = json.stringOf("items[i].created");
        updated = json.stringOf("items[i].updated");
        summary = json.stringOf("items[i].summary");
        description = json.stringOf("items[i].description");
        location = json.stringOf("items[i].location");
        creatorEmail = json.stringOf("items[i].creator.email");
        creatorSelf = json.BoolOf("items[i].creator.self");
        organizerEmail = json.stringOf("items[i].organizer.email");
        organizerSelf = json.BoolOf("items[i].organizer.self");
        startDateTime = json.stringOf("items[i].start.dateTime");
        startTimeZone = json.stringOf("items[i].start.timeZone");
        endDateTime = json.stringOf("items[i].end.dateTime");
        endTimeZone = json.stringOf("items[i].end.timeZone");
        recurringEventId = json.stringOf("items[i].recurringEventId");
        originalStartTimeDateTime = json.stringOf("items[i].originalStartTime.dateTime");
        originalStartTimeTimeZone = json.stringOf("items[i].originalStartTime.timeZone");
        iCalUID = json.stringOf("items[i].iCalUID");
        sequence = json.IntOf("items[i].sequence");
        hangoutLink = json.stringOf("items[i].hangoutLink");
        remindersUseDefault = json.BoolOf("items[i].reminders.useDefault");
        j = 0;
        count_j = json.SizeOfArray("items[i].reminders.overrides");
        while (j < count_j) {
            json.put_J(j);
            method = json.stringOf("items[i].reminders.overrides[j].method");
            minutes = json.IntOf("items[i].reminders.overrides[j].minutes");
            j = j + 1;
            }

        i = i + 1;
        }

    Log.i(TAG, "Example Completed.");

  }

  static {
      System.loadLibrary("chilkat");

      // Note: If the incorrect library name is passed to System.loadLibrary,
      // then you will see the following error message at application startup:
      //"The application <your-application-name> has stopped unexpectedly. Please try again."
  }
}

Sample JSON Response Body

{
  "kind": "calendar#events",
  "etag": "\"p33se7k7armnte0g\"",
  "summary": "support@chilkatcloud.com",
  "updated": "2017-11-08T19:40:49.131Z",
  "timeZone": "America/Chicago",
  "accessRole": "owner",
  "defaultReminders": [
    {
      "method": "popup",
      "minutes": 10
    }
  ],
  "nextSyncToken": "CPjj0Ordr9cCEPjj0Ordr9cCGAU=",
  "items": [
    {
      "kind": "calendar#event",
      "etag": "\"3020339874608000\"",
      "id": "6li3bfqqq65edprt4ms6vdld2j_20171111T000000Z",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NmxpM2JmcXFxNjVlZHBydDRtczZ2ZGxkMmpfMjAxNzExMTFUMDAwMDAwWiBzdXBwb3J0QGNoaWxrYXRjbG91ZC5jb20",
      "created": "2017-11-08T19:35:30.000Z",
      "updated": "2017-11-08T19:40:49.019Z",
      "summary": "TGIF Happy Hour",
      "description": "Friday Night Happy Hour",
      "location": "Shannon's Irish Pub, 428 N Main St, Glen Ellyn, IL 60137, USA",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-10T18:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "end": {
        "dateTime": "2017-11-10T19:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "recurringEventId": "6li3bfqqq65edprt4ms6vdld2j",
      "originalStartTime": {
        "dateTime": "2017-11-10T18:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "iCalUID": "6li3bfqqq65edprt4ms6vdld2j@google.com",
      "sequence": 1,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.6li3bfqqq65edprt4ms6vdld2j",
      "reminders": {
        "useDefault": false,
        "overrides": [
          {
            "method": "popup",
            "minutes": 180
          }
        ]
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020339874608000\"",
      "id": "6li3bfqqq65edprt4ms6vdld2j_20171118T000000Z",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NmxpM2JmcXFxNjVlZHBydDRtczZ2ZGxkMmpfMjAxNzExMThUMDAwMDAwWiBzdXBwb3J0QGNoaWxrYXRjbG91ZC5jb20",
      "created": "2017-11-08T19:35:30.000Z",
      "updated": "2017-11-08T19:40:49.019Z",
      "summary": "TGIF Happy Hour",
      "description": "Friday Night Happy Hour",
      "location": "Shannon's Irish Pub, 428 N Main St, Glen Ellyn, IL 60137, USA",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-17T18:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "end": {
        "dateTime": "2017-11-17T19:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "recurringEventId": "6li3bfqqq65edprt4ms6vdld2j",
      "originalStartTime": {
        "dateTime": "2017-11-17T18:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "iCalUID": "6li3bfqqq65edprt4ms6vdld2j@google.com",
      "sequence": 1,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.6li3bfqqq65edprt4ms6vdld2j",
      "reminders": {
        "useDefault": false,
        "overrides": [
          {
            "method": "popup",
            "minutes": 180
          }
        ]
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020339874608000\"",
      "id": "6li3bfqqq65edprt4ms6vdld2j_20171125T000000Z",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NmxpM2JmcXFxNjVlZHBydDRtczZ2ZGxkMmpfMjAxNzExMjVUMDAwMDAwWiBzdXBwb3J0QGNoaWxrYXRjbG91ZC5jb20",
      "created": "2017-11-08T19:35:30.000Z",
      "updated": "2017-11-08T19:40:49.019Z",
      "summary": "TGIF Happy Hour",
      "description": "Friday Night Happy Hour",
      "location": "Shannon's Irish Pub, 428 N Main St, Glen Ellyn, IL 60137, USA",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-11-24T18:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "end": {
        "dateTime": "2017-11-24T19:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "recurringEventId": "6li3bfqqq65edprt4ms6vdld2j",
      "originalStartTime": {
        "dateTime": "2017-11-24T18:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "iCalUID": "6li3bfqqq65edprt4ms6vdld2j@google.com",
      "sequence": 1,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.6li3bfqqq65edprt4ms6vdld2j",
      "reminders": {
        "useDefault": false,
        "overrides": [
          {
            "method": "popup",
            "minutes": 180
          }
        ]
      }
    },
    {
      "kind": "calendar#event",
      "etag": "\"3020339874608000\"",
      "id": "6li3bfqqq65edprt4ms6vdld2j_20171202T000000Z",
      "status": "confirmed",
      "htmlLink": "https://www.google.com/calendar/event?eid=NmxpM2JmcXFxNjVlZHBydDRtczZ2ZGxkMmpfMjAxNzEyMDJUMDAwMDAwWiBzdXBwb3J0QGNoaWxrYXRjbG91ZC5jb20",
      "created": "2017-11-08T19:35:30.000Z",
      "updated": "2017-11-08T19:40:49.019Z",
      "summary": "TGIF Happy Hour",
      "description": "Friday Night Happy Hour",
      "location": "Shannon's Irish Pub, 428 N Main St, Glen Ellyn, IL 60137, USA",
      "creator": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "organizer": {
        "email": "support@chilkatcloud.com",
        "self": true
      },
      "start": {
        "dateTime": "2017-12-01T18:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "end": {
        "dateTime": "2017-12-01T19:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "recurringEventId": "6li3bfqqq65edprt4ms6vdld2j",
      "originalStartTime": {
        "dateTime": "2017-12-01T18:00:00-06:00",
        "timeZone": "America/Chicago"
      },
      "iCalUID": "6li3bfqqq65edprt4ms6vdld2j@google.com",
      "sequence": 1,
      "hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.6li3bfqqq65edprt4ms6vdld2j",
      "reminders": {
        "useDefault": false,
        "overrides": [
          {
            "method": "popup",
            "minutes": 180
          }
        ]
      }
    }
  ]
}