Returns entries on the user's calendar list.
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
DECLARE @sbJson int
EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbJson OUT
EXEC sp_OAMethod @rest, 'FullRequestNoBodySb', @success OUT, 'GET', '/calendar/v3/users/me/calendarList', 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 @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 @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 @nextSyncToken nvarchar(4000)
DECLARE @i int
DECLARE @count_i int
DECLARE @id nvarchar(4000)
DECLARE @summary nvarchar(4000)
DECLARE @timeZone nvarchar(4000)
DECLARE @colorId nvarchar(4000)
DECLARE @backgroundColor nvarchar(4000)
DECLARE @foregroundColor nvarchar(4000)
DECLARE @selected int
DECLARE @accessRole nvarchar(4000)
DECLARE @primary int
DECLARE @j int
DECLARE @count_j int
DECLARE @method nvarchar(4000)
DECLARE @minutes int
DECLARE @type nvarchar(4000)
EXEC sp_OAMethod @json, 'StringOf', @kind OUT, 'kind'
EXEC sp_OAMethod @json, 'StringOf', @etag OUT, 'etag'
EXEC sp_OAMethod @json, 'StringOf', @nextSyncToken OUT, 'nextSyncToken'
SELECT @i = 0
EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'items'
WHILE STR(@i) < STR(@count_i)
BEGIN
EXEC sp_OASetProperty @json, 'I', STR(@i)
EXEC sp_OAMethod @json, 'StringOf', @kind OUT, 'items[i].kind'
EXEC sp_OAMethod @json, 'StringOf', @etag OUT, 'items[i].etag'
EXEC sp_OAMethod @json, 'StringOf', @id OUT, 'items[i].id'
EXEC sp_OAMethod @json, 'StringOf', @summary OUT, 'items[i].summary'
EXEC sp_OAMethod @json, 'StringOf', @timeZone OUT, 'items[i].timeZone'
EXEC sp_OAMethod @json, 'StringOf', @colorId OUT, 'items[i].colorId'
EXEC sp_OAMethod @json, 'StringOf', @backgroundColor OUT, 'items[i].backgroundColor'
EXEC sp_OAMethod @json, 'StringOf', @foregroundColor OUT, 'items[i].foregroundColor'
EXEC sp_OAMethod @json, 'BoolOf', @selected OUT, 'items[i].selected'
EXEC sp_OAMethod @json, 'StringOf', @accessRole OUT, 'items[i].accessRole'
EXEC sp_OAMethod @json, 'BoolOf', @primary OUT, 'items[i].primary'
SELECT @j = 0
EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'items[i].defaultReminders'
WHILE STR(@j) < STR(@count_j)
BEGIN
EXEC sp_OASetProperty @json, 'J', STR(@j)
EXEC sp_OAMethod @json, 'StringOf', @method OUT, 'items[i].defaultReminders[j].method'
EXEC sp_OAMethod @json, 'IntOf', @minutes OUT, 'items[i].defaultReminders[j].minutes'
SELECT @j = STR(@j) + 1
END
SELECT @j = 0
EXEC sp_OAMethod @json, 'SizeOfArray', @count_j OUT, 'items[i].notificationSettings.notifications'
WHILE STR(@j) < STR(@count_j)
BEGIN
EXEC sp_OASetProperty @json, 'J', STR(@j)
EXEC sp_OAMethod @json, 'StringOf', @type OUT, 'items[i].notificationSettings.notifications[j].type'
EXEC sp_OAMethod @json, 'StringOf', @method OUT, 'items[i].notificationSettings.notifications[j].method'
SELECT @j = STR(@j) + 1
END
SELECT @i = STR(@i) + 1
END
PRINT 'Example Completed.'
EXEC @hr = sp_OADestroy @rest
EXEC @hr = sp_OADestroy @oauth2
EXEC @hr = sp_OADestroy @sbJson
EXEC @hr = sp_OADestroy @json
END
GO
{
"kind": "calendar#calendarList",
"etag": "\"p33gdfl6bualde0g\"",
"nextSyncToken": "CODX1MvyqtcCEhhzdXBwb3J0QGNoaWxrYXRjbG91ZC5jb20=",
"items": [
{
"kind": "calendar#calendarListEntry",
"etag": "\"1465249947472000\"",
"id": "support@chilkatcloud.com",
"summary": "support@chilkatcloud.com",
"timeZone": "America/Chicago",
"colorId": "14",
"backgroundColor": "#9fe1e7",
"foregroundColor": "#000000",
"selected": true,
"accessRole": "owner",
"defaultReminders": [
{
"method": "popup",
"minutes": 10
}
],
"notificationSettings": {
"notifications": [
{
"type": "eventCreation",
"method": "email"
},
{
"type": "eventChange",
"method": "email"
},
{
"type": "eventCancellation",
"method": "email"
},
{
"type": "eventResponse",
"method": "email"
}
]
},
"primary": true
},
{
"kind": "calendar#calendarListEntry",
"etag": "\"1502373382732000\"",
"id": "#contacts@group.v.calendar.google.com",
"summary": "Contacts",
"timeZone": "America/Chicago",
"colorId": "13",
"backgroundColor": "#92e1c0",
"foregroundColor": "#000000",
"selected": true,
"accessRole": "reader",
"defaultReminders": []
},
{
"kind": "calendar#calendarListEntry",
"etag": "\"1502373376447000\"",
"id": "en.usa#holiday@group.v.calendar.google.com",
"summary": "Holidays in United States",
"timeZone": "America/Chicago",
"colorId": "8",
"backgroundColor": "#16a765",
"foregroundColor": "#000000",
"selected": true,
"accessRole": "reader",
"defaultReminders": []
}
]
}