PureBasic 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


IncludeFile "CkJsonObject.pb"
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"
IncludeFile "CkOAuth2.pb"

Procedure ChilkatExample()

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success.i

    ;   Provide a previously obtained OAuth2 access token.
    oauth2.i = CkOAuth2::ckCreate()
    If oauth2.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkOAuth2::setCkAccessToken(oauth2, "OAUTH2_ACCESS_TOKEN")
    CkRest::ckSetAuthOAuth2(rest,oauth2)

    success = CkRest::ckConnect(rest,"www.googleapis.com",443,1,1)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkOAuth2::ckDispose(oauth2)
        ProcedureReturn
    EndIf

    sbJson.i = CkStringBuilder::ckCreate()
    If sbJson.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkRest::ckFullRequestNoBodySb(rest,"GET","/calendar/v3/colors",sbJson)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkOAuth2::ckDispose(oauth2)
        CkStringBuilder::ckDispose(sbJson)
        ProcedureReturn
    EndIf

    If CkRest::ckResponseStatusCode(rest) <> 200
        Debug "Received error response code: " + Str(CkRest::ckResponseStatusCode(rest))
        Debug "Response body:"
        Debug CkStringBuilder::ckGetAsString(sbJson)
        CkRest::ckDispose(rest)
        CkOAuth2::ckDispose(oauth2)
        CkStringBuilder::ckDispose(sbJson)
        ProcedureReturn
    EndIf

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(json,sbJson)

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

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

    Debug "Example Completed."


    CkRest::ckDispose(rest)
    CkOAuth2::ckDispose(oauth2)
    CkStringBuilder::ckDispose(sbJson)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure

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"
    }
  }
}