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 Calendar Create EventCreates a new event in a specified calendar. For more details, see https://docs.microsoft.com/en-us/graph/api/calendar-post-events?view=graph-rest-1.0
#include <CkHttpW.h> #include <CkJsonObjectW.h> #include <CkHttpResponseW.h> void ChilkatSample(void) { // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttpW http; // Use your previously obtained access token as shown here: // Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope. CkJsonObjectW jsonToken; bool success = jsonToken.LoadFile(L"qa_data/tokens/msGraphCalendar.json"); if (success == false) { wprintf(L"%s\n",jsonToken.lastErrorText()); return; } http.put_AuthToken(jsonToken.stringOf(L"access_token")); // Create a JSON body for the HTTP POST // Use this online tool to generate the code from sample JSON: // Generate Code to Create JSON // { // "subject": "Let's go for lunch", // "body": { // "contentType": "HTML", // "content": "Does mid month work for you?" // }, // "start": { // "dateTime": "2019-11-15T12:00:00", // "timeZone": "Pacific Standard Time" // }, // "end": { // "dateTime": "2019-11-15T14:00:00", // "timeZone": "Pacific Standard Time" // }, // "location":{ // "displayName":"Harry's Bar" // }, // "attendees": [ // { // "emailAddress": { // "address":"adelev@contoso.onmicrosoft.com", // "name": "Adele Vance" // }, // "type": "required" // } // ] // } CkJsonObjectW json; json.UpdateString(L"subject",L"Let's go for lunch"); json.UpdateString(L"body.contentType",L"HTML"); json.UpdateString(L"body.content",L"Does mid month work for you?"); json.UpdateString(L"start.dateTime",L"2019-11-15T12:00:00"); json.UpdateString(L"start.timeZone",L"Pacific Standard Time"); json.UpdateString(L"end.dateTime",L"2019-11-15T14:00:00"); json.UpdateString(L"end.timeZone",L"Pacific Standard Time"); json.UpdateString(L"location.displayName",L"Harry's Bar"); json.UpdateString(L"attendees[0].emailAddress.address",L"adelev@contoso.onmicrosoft.com"); json.UpdateString(L"attendees[0].emailAddress.name",L"Adele Vance"); json.UpdateString(L"attendees[0].type",L"required"); // POST the JSON to https://graph.microsoft.com/v1.0/me/calendars/{id}/events // This is posting to a calendar in the default calendarGroup. // Specify the calendar id http.SetUrlVar(L"id",L"AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA=="); CkHttpResponseW *resp = http.PostJson3(L"https://graph.microsoft.com/v1.0/me/calendars/{$id}/events",L"application/json",json); if (http.get_LastMethodSuccess() == false) { wprintf(L"%s\n",http.lastErrorText()); return; } json.Load(resp->bodyStr()); json.put_EmitCompact(false); if (resp->get_StatusCode() != 201) { wprintf(L"%s\n",json.emit()); wprintf(L"Failed, response status code = %d\n",resp->get_StatusCode()); delete resp; return; } delete resp; wprintf(L"%s\n",json.emit()); // A sample response: // (See code for parsing this response below..) // { // "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/calendars('AQMkADAwATM0MDAAMS ... AClEpRTgAAAA%3D%3D')/events/$entity", // "@odata.etag": "W/\"5+vF7TKKdE6bGCRqXyl2PQAClIgmmw==\"", // "id": "AQMkADAwAT ... ApRZ7JkAAAA=", // "createdDateTime": "2019-04-26T14:31:39.8791929Z", // "lastModifiedDateTime": "2019-04-26T14:31:41.2753537Z", // "changeKey": "5+vF7TKKdE6bGCRqXyl2PQAClIgmmw==", // "categories": [ // ], // "originalStartTimeZone": "Pacific Standard Time", // "originalEndTimeZone": "Pacific Standard Time", // "iCalUId": "040000008200E00074C5B7101A82E00800000000F05DF1C23CFCD40100000000000000001000000009911D155F71EF42A230FEBFE5F7486A", // "reminderMinutesBeforeStart": 15, // "isReminderOn": true, // "hasAttachments": false, // "subject": "Let's go for lunch", // "bodyPreview": "Does mid month work for you?", // "importance": "normal", // "sensitivity": "normal", // "isAllDay": false, // "isCancelled": false, // "isOrganizer": true, // "responseRequested": true, // "seriesMasterId": null, // "showAs": "busy", // "type": "singleInstance", // "webLink": "https://outlook.live.com/owa/?itemid=AQMkADAwATM0MDAAMS1iNTcwL...pRZ7JkAAAA%3D&exvsurl=1&path=/calendar/item", // "onlineMeetingUrl": null, // "recurrence": null, // "responseStatus": { // "response": "organizer", // "time": "0001-01-01T00:00:00Z" // }, // "body": { // "contentType": "html", // "content": "<html>\r\n<head>\r\n<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n<meta content=\"text/html; charset=us-ascii\">\r\n</head>\r\n<body>\r\nDoes mid month work for you?\r\n</body>\r\n</html>\r\n" // }, // "start": { // "dateTime": "2019-11-15T12:00:00.0000000", // "timeZone": "Pacific Standard Time" // }, // "end": { // "dateTime": "2019-11-15T14:00:00.0000000", // "timeZone": "Pacific Standard Time" // }, // "location": { // "displayName": "Harry's Bar", // "locationType": "default", // "uniqueId": "Harry's Bar", // "uniqueIdType": "private" // }, // "locations": [ // { // "displayName": "Harry's Bar", // "locationType": "default", // "uniqueId": "Harry's Bar", // "uniqueIdType": "private" // } // ], // "attendees": [ // { // "type": "required", // "status": { // "response": "none", // "time": "0001-01-01T00:00:00Z" // }, // "emailAddress": { // "name": "Adele Vance", // "address": "adelev@contoso.onmicrosoft.com" // } // } // ], // "organizer": { // "emailAddress": { // "name": "Matt", // "address": "outlook_3A33FCEB9B74CC15@outlook.com" // } // } // } // // // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON const wchar_t *displayName = 0; const wchar_t *locationType = 0; const wchar_t *uniqueId = 0; const wchar_t *uniqueIdType = 0; const wchar_t *statusResponse = 0; const wchar_t *statusTime = 0; const wchar_t *emailAddressName = 0; const wchar_t *emailAddressAddress = 0; const wchar_t *odataContext = json.stringOf(L"\"@odata.context\""); const wchar_t *odataEtag = json.stringOf(L"\"@odata.etag\""); const wchar_t *id = json.stringOf(L"id"); const wchar_t *createdDateTime = json.stringOf(L"createdDateTime"); const wchar_t *lastModifiedDateTime = json.stringOf(L"lastModifiedDateTime"); const wchar_t *changeKey = json.stringOf(L"changeKey"); const wchar_t *originalStartTimeZone = json.stringOf(L"originalStartTimeZone"); const wchar_t *originalEndTimeZone = json.stringOf(L"originalEndTimeZone"); const wchar_t *iCalUId = json.stringOf(L"iCalUId"); const wchar_t *reminderMinutesBeforeStart = json.IntOf(L"reminderMinutesBeforeStart"); const wchar_t *isReminderOn = json.BoolOf(L"isReminderOn"); const wchar_t *hasAttachments = json.BoolOf(L"hasAttachments"); const wchar_t *subject = json.stringOf(L"subject"); const wchar_t *bodyPreview = json.stringOf(L"bodyPreview"); const wchar_t *importance = json.stringOf(L"importance"); const wchar_t *sensitivity = json.stringOf(L"sensitivity"); const wchar_t *isAllDay = json.BoolOf(L"isAllDay"); const wchar_t *isCancelled = json.BoolOf(L"isCancelled"); const wchar_t *isOrganizer = json.BoolOf(L"isOrganizer"); const wchar_t *responseRequested = json.BoolOf(L"responseRequested"); const wchar_t *seriesMasterId = json.stringOf(L"seriesMasterId"); const wchar_t *showAs = json.stringOf(L"showAs"); const wchar_t *type = json.stringOf(L"type"); const wchar_t *webLink = json.stringOf(L"webLink"); const wchar_t *onlineMeetingUrl = json.stringOf(L"onlineMeetingUrl"); const wchar_t *recurrence = json.stringOf(L"recurrence"); const wchar_t *responseStatusResponse = json.stringOf(L"responseStatus.response"); const wchar_t *responseStatusTime = json.stringOf(L"responseStatus.time"); const wchar_t *bodyContentType = json.stringOf(L"body.contentType"); const wchar_t *bodyContent = json.stringOf(L"body.content"); const wchar_t *startDateTime = json.stringOf(L"start.dateTime"); const wchar_t *startTimeZone = json.stringOf(L"start.timeZone"); const wchar_t *endDateTime = json.stringOf(L"end.dateTime"); const wchar_t *endTimeZone = json.stringOf(L"end.timeZone"); const wchar_t *locationDisplayName = json.stringOf(L"location.displayName"); const wchar_t *locationLocationType = json.stringOf(L"location.locationType"); const wchar_t *locationUniqueId = json.stringOf(L"location.uniqueId"); const wchar_t *locationUniqueIdType = json.stringOf(L"location.uniqueIdType"); const wchar_t *organizerEmailAddressName = json.stringOf(L"organizer.emailAddress.name"); const wchar_t *organizerEmailAddressAddress = json.stringOf(L"organizer.emailAddress.address"); int i = 0; int count_i = json.SizeOfArray(L"categories"); while (i < count_i) { json.put_I(i); // ... i = i + 1; } i = 0; count_i = json.SizeOfArray(L"locations"); while (i < count_i) { json.put_I(i); displayName = json.stringOf(L"locations[i].displayName"); locationType = json.stringOf(L"locations[i].locationType"); uniqueId = json.stringOf(L"locations[i].uniqueId"); uniqueIdType = json.stringOf(L"locations[i].uniqueIdType"); i = i + 1; } i = 0; count_i = json.SizeOfArray(L"attendees"); while (i < count_i) { json.put_I(i); type = json.stringOf(L"attendees[i].type"); statusResponse = json.stringOf(L"attendees[i].status.response"); statusTime = json.stringOf(L"attendees[i].status.time"); emailAddressName = json.stringOf(L"attendees[i].emailAddress.name"); emailAddressAddress = json.stringOf(L"attendees[i].emailAddress.address"); i = i + 1; } wprintf(L"Success.\n"); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.