Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(SQL Server) MS Graph Calendars ListGet all the user's calendars (/calendars navigation property), get the calendars from the default calendar group or from a specific calendar group. For more details, see https://docs.microsoft.com/en-us/graph/api/user-list-calendars?view=graph-rest-1.0
-- Important: See this note about string length limitations for strings returned by sp_OAMethod calls. -- CREATE PROCEDURE ChilkatSample AS BEGIN DECLARE @hr int DECLARE @iTmp0 int -- Important: Do not use nvarchar(max). See the warning about using nvarchar(max). DECLARE @sTmp0 nvarchar(4000) -- This example requires the Chilkat API to have been previously unlocked. -- See Global Unlock Sample for sample code. DECLARE @http int -- Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.Http', @http OUT IF @hr <> 0 BEGIN PRINT 'Failed to create ActiveX component' RETURN END -- Use your previously obtained access token as shown here: -- Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope. DECLARE @jsonToken int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @jsonToken OUT DECLARE @success int EXEC sp_OAMethod @jsonToken, 'LoadFile', @success OUT, 'qa_data/tokens/msGraphCalendar.json' IF @success = 0 BEGIN EXEC sp_OAGetProperty @jsonToken, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken RETURN END EXEC sp_OAMethod @jsonToken, 'StringOf', @sTmp0 OUT, 'access_token' EXEC sp_OASetProperty @http, 'AuthToken', @sTmp0 -- Send a GET request to https://graph.microsoft.com/v1.0/me/calendars DECLARE @strResponse nvarchar(4000) EXEC sp_OAMethod @http, 'QuickGetStr', @strResponse OUT, 'https://graph.microsoft.com/v1.0/me/calendars' EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT IF @iTmp0 = 0 BEGIN EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT PRINT @sTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken RETURN END DECLARE @json int -- Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 EXEC @hr = sp_OACreate 'Chilkat.JsonObject', @json OUT EXEC sp_OAMethod @json, 'Load', @success OUT, @strResponse EXEC sp_OASetProperty @json, 'EmitCompact', 0 EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT IF @iTmp0 <> 200 BEGIN EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT PRINT 'Failed, response status code = ' + @iTmp0 EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @json RETURN END EXEC sp_OAMethod @json, 'Emit', @sTmp0 OUT PRINT @sTmp0 -- Sample output: -- { -- "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/calendars", -- "value": [ -- { -- "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAAAiCsAAAA", -- "name": "Calendar", -- "color": "auto", -- "changeKey": "5+vF7TKKdE6bGCRqXyl2PQAAAAAiEQ==", -- "canShare": true, -- "canViewPrivateItems": true, -- "canEdit": true, -- "owner": { -- "name": "...", -- "address": "outlook_3A33FCEB9B74CC15@outlook.com" -- } -- }, -- { -- "id": "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==", -- "name": "Work", -- "color": "auto", -- "changeKey": "5+vF7TKKdE6bGCRqXyl2PQAClHjDcA==", -- "canShare": true, -- "canViewPrivateItems": true, -- "canEdit": true, -- "owner": { -- "name": "...", -- "address": "outlook_3A33FCEB9B74CC15@outlook.com" -- } -- } -- ] -- } -- -- Use this online tool to generate parsing code from sample JSON: -- Generate Parsing Code from JSON DECLARE @odataContext nvarchar(4000) DECLARE @i int DECLARE @count_i int DECLARE @id nvarchar(4000) DECLARE @name nvarchar(4000) DECLARE @color nvarchar(4000) DECLARE @changeKey nvarchar(4000) DECLARE @canShare int DECLARE @canViewPrivateItems int DECLARE @canEdit int DECLARE @ownerName nvarchar(4000) DECLARE @ownerAddress nvarchar(4000) EXEC sp_OAMethod @json, 'StringOf', @odataContext OUT, '"@odata.context"' SELECT @i = 0 EXEC sp_OAMethod @json, 'SizeOfArray', @count_i OUT, 'value' WHILE @i < @count_i BEGIN EXEC sp_OASetProperty @json, 'I', @i EXEC sp_OAMethod @json, 'StringOf', @id OUT, 'value[i].id' EXEC sp_OAMethod @json, 'StringOf', @name OUT, 'value[i].name' EXEC sp_OAMethod @json, 'StringOf', @color OUT, 'value[i].color' EXEC sp_OAMethod @json, 'StringOf', @changeKey OUT, 'value[i].changeKey' EXEC sp_OAMethod @json, 'BoolOf', @canShare OUT, 'value[i].canShare' EXEC sp_OAMethod @json, 'BoolOf', @canViewPrivateItems OUT, 'value[i].canViewPrivateItems' EXEC sp_OAMethod @json, 'BoolOf', @canEdit OUT, 'value[i].canEdit' EXEC sp_OAMethod @json, 'StringOf', @ownerName OUT, 'value[i].owner.name' EXEC sp_OAMethod @json, 'StringOf', @ownerAddress OUT, 'value[i].owner.address' SELECT @i = @i + 1 END PRINT 'Success.' EXEC @hr = sp_OADestroy @http EXEC @hr = sp_OADestroy @jsonToken EXEC @hr = sp_OADestroy @json END GO |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.