Swift Google Calendar: Get Color Definitions

Back to Index

Returns the color definitions for calendars and events.

Documentation: https://developers.google.com/google-apps/calendar/v3/reference/colors/get



func chilkatTest() {
    let rest = CkoRest()
    var success: Bool

    //   Provide a previously obtained OAuth2 access token.
    let oauth2 = CkoOAuth2()
    oauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
    rest.SetAuthOAuth2(oauth2)

    success = rest.Connect("www.googleapis.com", port: 443, tls: true, autoReconnect: true)
    if success != true {
        print("\(rest.LastErrorText)")
        return
    }

    let sbJson = CkoStringBuilder()
    success = rest.FullRequestNoBodySb("GET", uriPath: "/calendar/v3/colors", sb: sbJson)
    if success != true {
        print("\(rest.LastErrorText)")
        return
    }

    if rest.ResponseStatusCode.integerValue != 200 {
        print("Received error response code: \(rest.ResponseStatusCode.integerValue)")
        print("Response body:")
        print("\(sbJson.GetAsString())")
        return
    }

    let json = CkoJsonObject()
    json.LoadSb(sbJson)

    //  The following code parses the JSON response.
    //  A sample JSON response is shown below the sample code.
    var kind: String?
    var updated: String?
    var calendar1Background: String?
    var calendar1Foreground: String?
    var calendar2Background: String?
    var calendar2Foreground: String?
    var calendar3Background: String?
    var calendar3Foreground: String?
    var calendar4Background: String?
    var calendar4Foreground: String?
    var calendar5Background: String?
    var calendar5Foreground: String?
    var calendar6Background: String?
    var calendar6Foreground: String?
    var calendar7Background: String?
    var calendar7Foreground: String?
    var calendar8Background: String?
    var calendar8Foreground: String?
    var calendar9Background: String?
    var calendar9Foreground: String?
    var calendar10Background: String?
    var calendar10Foreground: String?
    var calendar11Background: String?
    var calendar11Foreground: String?
    var calendar12Background: String?
    var calendar12Foreground: String?
    var calendar13Background: String?
    var calendar13Foreground: String?
    var calendar14Background: String?
    var calendar14Foreground: String?
    var calendar15Background: String?
    var calendar15Foreground: String?
    var calendar16Background: String?
    var calendar16Foreground: String?
    var calendar17Background: String?
    var calendar17Foreground: String?
    var calendar18Background: String?
    var calendar18Foreground: String?
    var calendar19Background: String?
    var calendar19Foreground: String?
    var calendar20Background: String?
    var calendar20Foreground: String?
    var calendar21Background: String?
    var calendar21Foreground: String?
    var calendar22Background: String?
    var calendar22Foreground: String?
    var calendar23Background: String?
    var calendar23Foreground: String?
    var calendar24Background: String?
    var calendar24Foreground: String?
    var event1Background: String?
    var event1Foreground: String?
    var event2Background: String?
    var event2Foreground: String?
    var event3Background: String?
    var event3Foreground: String?
    var event4Background: String?
    var event4Foreground: String?
    var event5Background: String?
    var event5Foreground: String?
    var event6Background: String?
    var event6Foreground: String?
    var event7Background: String?
    var event7Foreground: String?
    var event8Background: String?
    var event8Foreground: String?
    var event9Background: String?
    var event9Foreground: String?
    var event10Background: String?
    var event10Foreground: String?
    var event11Background: String?
    var event11Foreground: String?

    kind = json.StringOf("kind")
    updated = json.StringOf("updated")
    calendar1Background = json.StringOf("calendar.1.background")
    calendar1Foreground = json.StringOf("calendar.1.foreground")
    calendar2Background = json.StringOf("calendar.2.background")
    calendar2Foreground = json.StringOf("calendar.2.foreground")
    calendar3Background = json.StringOf("calendar.3.background")
    calendar3Foreground = json.StringOf("calendar.3.foreground")
    calendar4Background = json.StringOf("calendar.4.background")
    calendar4Foreground = json.StringOf("calendar.4.foreground")
    calendar5Background = json.StringOf("calendar.5.background")
    calendar5Foreground = json.StringOf("calendar.5.foreground")
    calendar6Background = json.StringOf("calendar.6.background")
    calendar6Foreground = json.StringOf("calendar.6.foreground")
    calendar7Background = json.StringOf("calendar.7.background")
    calendar7Foreground = json.StringOf("calendar.7.foreground")
    calendar8Background = json.StringOf("calendar.8.background")
    calendar8Foreground = json.StringOf("calendar.8.foreground")
    calendar9Background = json.StringOf("calendar.9.background")
    calendar9Foreground = json.StringOf("calendar.9.foreground")
    calendar10Background = json.StringOf("calendar.10.background")
    calendar10Foreground = json.StringOf("calendar.10.foreground")
    calendar11Background = json.StringOf("calendar.11.background")
    calendar11Foreground = json.StringOf("calendar.11.foreground")
    calendar12Background = json.StringOf("calendar.12.background")
    calendar12Foreground = json.StringOf("calendar.12.foreground")
    calendar13Background = json.StringOf("calendar.13.background")
    calendar13Foreground = json.StringOf("calendar.13.foreground")
    calendar14Background = json.StringOf("calendar.14.background")
    calendar14Foreground = json.StringOf("calendar.14.foreground")
    calendar15Background = json.StringOf("calendar.15.background")
    calendar15Foreground = json.StringOf("calendar.15.foreground")
    calendar16Background = json.StringOf("calendar.16.background")
    calendar16Foreground = json.StringOf("calendar.16.foreground")
    calendar17Background = json.StringOf("calendar.17.background")
    calendar17Foreground = json.StringOf("calendar.17.foreground")
    calendar18Background = json.StringOf("calendar.18.background")
    calendar18Foreground = json.StringOf("calendar.18.foreground")
    calendar19Background = json.StringOf("calendar.19.background")
    calendar19Foreground = json.StringOf("calendar.19.foreground")
    calendar20Background = json.StringOf("calendar.20.background")
    calendar20Foreground = json.StringOf("calendar.20.foreground")
    calendar21Background = json.StringOf("calendar.21.background")
    calendar21Foreground = json.StringOf("calendar.21.foreground")
    calendar22Background = json.StringOf("calendar.22.background")
    calendar22Foreground = json.StringOf("calendar.22.foreground")
    calendar23Background = json.StringOf("calendar.23.background")
    calendar23Foreground = json.StringOf("calendar.23.foreground")
    calendar24Background = json.StringOf("calendar.24.background")
    calendar24Foreground = json.StringOf("calendar.24.foreground")
    event1Background = json.StringOf("event.1.background")
    event1Foreground = json.StringOf("event.1.foreground")
    event2Background = json.StringOf("event.2.background")
    event2Foreground = json.StringOf("event.2.foreground")
    event3Background = json.StringOf("event.3.background")
    event3Foreground = json.StringOf("event.3.foreground")
    event4Background = json.StringOf("event.4.background")
    event4Foreground = json.StringOf("event.4.foreground")
    event5Background = json.StringOf("event.5.background")
    event5Foreground = json.StringOf("event.5.foreground")
    event6Background = json.StringOf("event.6.background")
    event6Foreground = json.StringOf("event.6.foreground")
    event7Background = json.StringOf("event.7.background")
    event7Foreground = json.StringOf("event.7.foreground")
    event8Background = json.StringOf("event.8.background")
    event8Foreground = json.StringOf("event.8.foreground")
    event9Background = json.StringOf("event.9.background")
    event9Foreground = json.StringOf("event.9.foreground")
    event10Background = json.StringOf("event.10.background")
    event10Foreground = json.StringOf("event.10.foreground")
    event11Background = json.StringOf("event.11.background")
    event11Foreground = json.StringOf("event.11.foreground")

    print("Example Completed.")

}

Sample JSON Response Body

{
  "kind": "calendar#colors",
  "updated": "2012-02-14T00:00:00.000Z",
  "calendar": {
    "1": {
      "background": "#ac725e",
      "foreground": "#1d1d1d"
    },
    "2": {
      "background": "#d06b64",
      "foreground": "#1d1d1d"
    },
    "3": {
      "background": "#f83a22",
      "foreground": "#1d1d1d"
    },
    "4": {
      "background": "#fa573c",
      "foreground": "#1d1d1d"
    },
    "5": {
      "background": "#ff7537",
      "foreground": "#1d1d1d"
    },
    "6": {
      "background": "#ffad46",
      "foreground": "#1d1d1d"
    },
    "7": {
      "background": "#42d692",
      "foreground": "#1d1d1d"
    },
    "8": {
      "background": "#16a765",
      "foreground": "#1d1d1d"
    },
    "9": {
      "background": "#7bd148",
      "foreground": "#1d1d1d"
    },
    "10": {
      "background": "#b3dc6c",
      "foreground": "#1d1d1d"
    },
    "11": {
      "background": "#fbe983",
      "foreground": "#1d1d1d"
    },
    "12": {
      "background": "#fad165",
      "foreground": "#1d1d1d"
    },
    "13": {
      "background": "#92e1c0",
      "foreground": "#1d1d1d"
    },
    "14": {
      "background": "#9fe1e7",
      "foreground": "#1d1d1d"
    },
    "15": {
      "background": "#9fc6e7",
      "foreground": "#1d1d1d"
    },
    "16": {
      "background": "#4986e7",
      "foreground": "#1d1d1d"
    },
    "17": {
      "background": "#9a9cff",
      "foreground": "#1d1d1d"
    },
    "18": {
      "background": "#b99aff",
      "foreground": "#1d1d1d"
    },
    "19": {
      "background": "#c2c2c2",
      "foreground": "#1d1d1d"
    },
    "20": {
      "background": "#cabdbf",
      "foreground": "#1d1d1d"
    },
    "21": {
      "background": "#cca6ac",
      "foreground": "#1d1d1d"
    },
    "22": {
      "background": "#f691b2",
      "foreground": "#1d1d1d"
    },
    "23": {
      "background": "#cd74e6",
      "foreground": "#1d1d1d"
    },
    "24": {
      "background": "#a47ae2",
      "foreground": "#1d1d1d"
    }
  },
  "event": {
    "1": {
      "background": "#a4bdfc",
      "foreground": "#1d1d1d"
    },
    "2": {
      "background": "#7ae7bf",
      "foreground": "#1d1d1d"
    },
    "3": {
      "background": "#dbadff",
      "foreground": "#1d1d1d"
    },
    "4": {
      "background": "#ff887c",
      "foreground": "#1d1d1d"
    },
    "5": {
      "background": "#fbd75b",
      "foreground": "#1d1d1d"
    },
    "6": {
      "background": "#ffb878",
      "foreground": "#1d1d1d"
    },
    "7": {
      "background": "#46d6db",
      "foreground": "#1d1d1d"
    },
    "8": {
      "background": "#e1e1e1",
      "foreground": "#1d1d1d"
    },
    "9": {
      "background": "#5484ed",
      "foreground": "#1d1d1d"
    },
    "10": {
      "background": "#51b749",
      "foreground": "#1d1d1d"
    },
    "11": {
      "background": "#dc2127",
      "foreground": "#1d1d1d"
    }
  }
}