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
(Unicode C) MS Graph Create CalendarCreates a new calendar. For more details, see https://docs.microsoft.com/en-us/graph/api/user-post-calendars?view=graph-rest-1.0
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpResponseW.h> void ChilkatSample(void) { HCkHttpW http; HCkJsonObjectW jsonToken; BOOL success; HCkJsonObjectW json; HCkHttpResponseW resp; const wchar_t *odataContext; const wchar_t *id; const wchar_t *name; const wchar_t *color; const wchar_t *changeKey; const wchar_t *canShare; const wchar_t *canViewPrivateItems; const wchar_t *canEdit; const wchar_t *ownerName; const wchar_t *ownerAddress; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // Use your previously obtained access token as shown here: // Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope. jsonToken = CkJsonObjectW_Create(); success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/msGraphCalendar.json"); if (success == FALSE) { wprintf(L"%s\n",CkJsonObjectW_lastErrorText(jsonToken)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); return; } CkHttpW_putAuthToken(http,CkJsonObjectW_stringOf(jsonToken,L"access_token")); // Create a JSON body for the HTTP POST // { // "name": "Work" // } json = CkJsonObjectW_Create(); CkJsonObjectW_UpdateString(json,L"name",L"Work"); // POST the JSON to https://graph.microsoft.com/v1.0/me/calendars resp = CkHttpW_PostJson3(http,L"https://graph.microsoft.com/v1.0/me/calendars",L"application/json",json); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(json); return; } CkJsonObjectW_Load(json,CkHttpResponseW_bodyStr(resp)); CkJsonObjectW_putEmitCompact(json,FALSE); if (CkHttpResponseW_getStatusCode(resp) != 201) { wprintf(L"%s\n",CkJsonObjectW_emit(json)); wprintf(L"Failed, response status code = %d\n",CkHttpResponseW_getStatusCode(resp)); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(json); return; } CkHttpResponseW_Dispose(resp); wprintf(L"%s\n",CkJsonObjectW_emit(json)); // A sample response: // { // "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/calendars/$entity", // "id": "AQMkAD...TgAAAA==", // "name": "Work", // "color": "auto", // "changeKey": "5+vF7T...HjDcA==", // "canShare": true, // "canViewPrivateItems": true, // "canEdit": true, // "owner": { // "name": "...", // "address": "outlook_3A33...4CC15@outlook.com" // } // } // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON odataContext = CkJsonObjectW_stringOf(json,L"\"@odata.context\""); id = CkJsonObjectW_stringOf(json,L"id"); name = CkJsonObjectW_stringOf(json,L"name"); color = CkJsonObjectW_stringOf(json,L"color"); changeKey = CkJsonObjectW_stringOf(json,L"changeKey"); canShare = CkJsonObjectW_BoolOf(json,L"canShare"); canViewPrivateItems = CkJsonObjectW_BoolOf(json,L"canViewPrivateItems"); canEdit = CkJsonObjectW_BoolOf(json,L"canEdit"); ownerName = CkJsonObjectW_stringOf(json,L"owner.name"); ownerAddress = CkJsonObjectW_stringOf(json,L"owner.address"); wprintf(L"Success.\n"); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(jsonToken); CkJsonObjectW_Dispose(json); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.