PureBasic Google Calendar: Delete an Event

Back to Index

Deletes an event from a calendar.
This example deletes an event from the calendar having the ID = "support@chilkatcloud.com". The event ID to be deleted is "1p7fb5vob7vm57fepk4p1teft9".
If successful, the response is empty and the response status code = 204.

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


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

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

    success = CkRest::ckFullRequestNoBodySb(rest,"DELETE","/calendar/v3/calendars/support@chilkatcloud.com/events/1p7fb5vob7vm57fepk4p1teft9",sbResponse)
    If success <> 1
        Debug CkRest::ckLastErrorText(rest)
        CkRest::ckDispose(rest)
        CkOAuth2::ckDispose(oauth2)
        CkStringBuilder::ckDispose(sbResponse)
        ProcedureReturn
    EndIf

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

    Debug "Example Completed."


    CkRest::ckDispose(rest)
    CkOAuth2::ckDispose(oauth2)
    CkStringBuilder::ckDispose(sbResponse)


    ProcedureReturn
EndProcedure