Creates an event based on a simple text string. (This example adds an event to the calendar with id = "support@chilkatcloud.com".)
CREATE PROCEDURE ChilkatSample
AS
BEGIN
DECLARE @hr int
DECLARE @iTmp0 int
DECLARE @sTmp0 nvarchar(4000)
DECLARE @rest int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Rest', @rest OUT
IF @hr <> 0
BEGIN
PRINT 'Failed to create ActiveX component'
RETURN
END
DECLARE @success int
-- Provide a previously obtained OAuth2 access token.
DECLARE @oauth2 int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.OAuth2', @oauth2 OUT
EXEC sp_OASetProperty @oauth2, 'AccessToken', 'OAUTH2_ACCESS_TOKEN'
EXEC sp_OAMethod @rest, 'SetAuthOAuth2', @success OUT, STR(@oauth2)
EXEC sp_OAMethod @rest, 'Connect', @success OUT, 'www.googleapis.com', 443, 1, 1
IF STR(@success) <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @oauth2
RETURN
END
EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'text', 'Dentist Appointment'
EXEC sp_OAMethod @rest, 'AddQueryParam', @success OUT, 'sendNotifications', 'true'
DECLARE @sbReq int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbReq OUT
DECLARE @sbJson int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbJson OUT
EXEC sp_OAMethod @rest, 'FullRequestSb', @success OUT, 'POST', '/calendar/v3/calendars/support@chilkatcloud.com/events/quickAdd', STR(@sbReq), STR(@sbJson)
IF STR(@success) <> 1
BEGIN
EXEC sp_OAGetProperty @rest, 'LastErrorText', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @oauth2
EXEC @hr = sp_OADestroy @sbReq
EXEC @hr = sp_OADestroy @sbJson
RETURN
END
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
IF @iTmp0 <> 200
BEGIN
EXEC sp_OAGetProperty @rest, 'ResponseStatusCode', @iTmp0 OUT
PRINT 'Received error response code: ' + @iTmp0
PRINT 'Response body:'
EXEC sp_OAMethod @sbJson, 'GetAsString', @sTmp0 OUT
PRINT @sTmp0
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @oauth2
EXEC @hr = sp_OADestroy @sbReq
EXEC @hr = sp_OADestroy @sbJson
RETURN
END
DECLARE @json int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT
EXEC sp_OAMethod @json, 'LoadSb', @success OUT, STR(@sbJson)
-- The following code parses the JSON response.
-- A sample JSON response is shown below the sample code.
DECLARE @kind nvarchar(4000)
DECLARE @etag nvarchar(4000)
DECLARE @id nvarchar(4000)
DECLARE @status nvarchar(4000)
DECLARE @htmlLink nvarchar(4000)
DECLARE @created nvarchar(4000)
DECLARE @updated nvarchar(4000)
DECLARE @summary nvarchar(4000)
DECLARE @creatorEmail nvarchar(4000)
DECLARE @creatorSelf int
DECLARE @organizerEmail nvarchar(4000)
DECLARE @organizerSelf int
DECLARE @startDateTime nvarchar(4000)
DECLARE @endDateTime nvarchar(4000)
DECLARE @iCalUID nvarchar(4000)
DECLARE @sequence int
DECLARE @hangoutLink nvarchar(4000)
DECLARE @remindersUseDefault int
EXEC sp_OAMethod @json, 'StringOf', @kind OUT, 'kind'
EXEC sp_OAMethod @json, 'StringOf', @etag OUT, 'etag'
EXEC sp_OAMethod @json, 'StringOf', @id OUT, 'id'
EXEC sp_OAMethod @json, 'StringOf', @status OUT, 'status'
EXEC sp_OAMethod @json, 'StringOf', @htmlLink OUT, 'htmlLink'
EXEC sp_OAMethod @json, 'StringOf', @created OUT, 'created'
EXEC sp_OAMethod @json, 'StringOf', @updated OUT, 'updated'
EXEC sp_OAMethod @json, 'StringOf', @summary OUT, 'summary'
EXEC sp_OAMethod @json, 'StringOf', @creatorEmail OUT, 'creator.email'
EXEC sp_OAMethod @json, 'BoolOf', @creatorSelf OUT, 'creator.self'
EXEC sp_OAMethod @json, 'StringOf', @organizerEmail OUT, 'organizer.email'
EXEC sp_OAMethod @json, 'BoolOf', @organizerSelf OUT, 'organizer.self'
EXEC sp_OAMethod @json, 'StringOf', @startDateTime OUT, 'start.dateTime'
EXEC sp_OAMethod @json, 'StringOf', @endDateTime OUT, 'end.dateTime'
EXEC sp_OAMethod @json, 'StringOf', @iCalUID OUT, 'iCalUID'
EXEC sp_OAMethod @json, 'IntOf', @sequence OUT, 'sequence'
EXEC sp_OAMethod @json, 'StringOf', @hangoutLink OUT, 'hangoutLink'
EXEC sp_OAMethod @json, 'BoolOf', @remindersUseDefault OUT, 'reminders.useDefault'
PRINT 'Example Completed.'
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @oauth2
EXEC @hr = sp_OADestroy @sbReq
EXEC @hr = sp_OADestroy @sbJson
EXEC @hr = sp_OADestroy @json
END
GO
{
"kind": "calendar#event",
"etag": "\"3020352941868000\"",
"id": "52e7uk7j7vl5dosj7b25memov0",
"status": "confirmed",
"htmlLink": "https://www.google.com/calendar/event?eid=NTJlN3VrN2o3dmw1ZG9zajdiMjVtZW1vdjAgc3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t",
"created": "2017-11-08T21:27:50.000Z",
"updated": "2017-11-08T21:27:50.934Z",
"summary": "Dentist Appointment",
"creator": {
"email": "support@chilkatcloud.com",
"self": true
},
"organizer": {
"email": "support@chilkatcloud.com",
"self": true
},
"start": {
"dateTime": "2017-11-08T15:27:50-06:00"
},
"end": {
"dateTime": "2017-11-08T16:27:50-06:00"
},
"iCalUID": "52e7uk7j7vl5dosj7b25memov0@google.com",
"sequence": 0,
"hangoutLink": "https://plus.google.com/hangouts/_/chilkatcloud.com/support?hceid=c3VwcG9ydEBjaGlsa2F0Y2xvdWQuY29t.52e7uk7j7vl5dosj7b25memov0",
"reminders": {
"useDefault": true
}
}