Visual FoxPro Google Calendar: Create (Insert) a Calendar

Back to Index

Creates a new calendar. (i.e. Adds an entry to the user's calendar list.)

Documentation: https://developers.google.com/google-apps/calendar/v3/reference/calendarList/insert


LOCAL loRest
LOCAL lnSuccess
LOCAL loOauth2
LOCAL loJsonReq
LOCAL loSbReq
LOCAL loSbJson
LOCAL loJson
LOCAL lcKind
LOCAL lcEtag
LOCAL lcId
LOCAL lcSummary

loRest = CreateObject('Chilkat_9_5_0.Rest')

*   Provide a previously obtained OAuth2 access token.
loOauth2 = CreateObject('Chilkat_9_5_0.OAuth2')
loOauth2.AccessToken = "OAUTH2_ACCESS_TOKEN"
loRest.SetAuthOAuth2(loOauth2)

lnSuccess = loRest.Connect("www.googleapis.com",443,1,1)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    CANCEL
ENDIF

*  The following code creates the JSON request body.
*  The JSON created by this code is shown below.
loJsonReq = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonReq.UpdateString("summary","test calendar abc")

loSbReq = CreateObject('Chilkat_9_5_0.StringBuilder')
loJsonReq.EmitSb(loSbReq)

loRest.AddHeader("Content-Type","application/json")

loSbJson = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestSb("POST","/calendar/v3/calendars",loSbReq,loSbJson)
IF (lnSuccess <> 1) THEN
    ? loRest.LastErrorText
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loJsonReq
    RELEASE loSbReq
    RELEASE loSbJson
    CANCEL
ENDIF

IF (loRest.ResponseStatusCode <> 200) THEN
    ? "Received error response code: " + STR(loRest.ResponseStatusCode)
    ? "Response body:"
    ? loSbJson.GetAsString()
    RELEASE loRest
    RELEASE loOauth2
    RELEASE loJsonReq
    RELEASE loSbReq
    RELEASE loSbJson
    CANCEL
ENDIF

loJson = CreateObject('Chilkat_9_5_0.JsonObject')
loJson.LoadSb(loSbJson)

*  The following code parses the JSON response.
*  A sample JSON response is shown below the sample code.

lcKind = loJson.StringOf("kind")
lcEtag = loJson.StringOf("etag")
lcId = loJson.StringOf("id")
lcSummary = loJson.StringOf("summary")

? "Example Completed."

RELEASE loRest
RELEASE loOauth2
RELEASE loJsonReq
RELEASE loSbReq
RELEASE loSbJson
RELEASE loJson

Sample JSON Request Body

  {
   "summary": "test calendar abc"
  }
  

Sample JSON Response Body

{
  "kind": "calendar#calendar",
  "etag": "\"BKjXnZpXR6E5ueFWG3UJk-2POYg/jb82ZwCZzTu1P_p3WnVVxDoJTeI\"",
  "id": "chilkatcloud.com_he3bfm0ljrl7p427u8vjmg9afo@group.calendar.google.com",
  "summary": "test calendar abc"
}