Delphi DLL
Delphi DLL
MS Graph Calendar List Events
See more Microsoft Calendar Examples
Retrieve a list of events in a calendar. The list contains single instance meetings and series masters.For more details, see https://docs.microsoft.com/en-us/graph/api/calendar-list-events?view=graph-rest-1.0
Chilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, JsonObject, Http;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
jsonToken: HCkJsonObject;
strResponse: PWideChar;
json: HCkJsonObject;
odataContext: PWideChar;
i: Integer;
count_i: Integer;
odataEtag: PWideChar;
id: PWideChar;
createdDateTime: PWideChar;
lastModifiedDateTime: PWideChar;
changeKey: PWideChar;
originalStartTimeZone: PWideChar;
originalEndTimeZone: PWideChar;
iCalUId: PWideChar;
reminderMinutesBeforeStart: Integer;
isReminderOn: Boolean;
hasAttachments: Boolean;
subject: PWideChar;
bodyPreview: PWideChar;
importance: PWideChar;
sensitivity: PWideChar;
isAllDay: Boolean;
isCancelled: Boolean;
isOrganizer: Boolean;
responseRequested: Boolean;
seriesMasterId: PWideChar;
showAs: PWideChar;
v_type: PWideChar;
webLink: PWideChar;
onlineMeetingUrl: PWideChar;
recurrence: PWideChar;
responseStatusResponse: PWideChar;
responseStatusTime: PWideChar;
bodyContentType: PWideChar;
bodyContent: PWideChar;
startDateTime: PWideChar;
startTimeZone: PWideChar;
endDateTime: PWideChar;
endTimeZone: PWideChar;
locationDisplayName: PWideChar;
locationLocationType: PWideChar;
locationUniqueId: PWideChar;
locationUniqueIdType: PWideChar;
organizerEmailAddressName: PWideChar;
organizerEmailAddressAddress: PWideChar;
j: Integer;
count_j: Integer;
displayName: PWideChar;
locationType: PWideChar;
uniqueId: PWideChar;
uniqueIdType: PWideChar;
statusResponse: PWideChar;
statusTime: PWideChar;
emailAddressName: PWideChar;
emailAddressAddress: PWideChar;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := CkHttp_Create();
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope.
jsonToken := CkJsonObject_Create();
success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/msGraphCalendar.json');
if (success = False) then
begin
Memo1.Lines.Add(CkJsonObject__lastErrorText(jsonToken));
Exit;
end;
CkHttp_putAuthToken(http,CkJsonObject__stringOf(jsonToken,'access_token'));
// Specify the calendar id
CkHttp_SetUrlVar(http,'id','AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==');
// Send a GET request to https://graph.microsoft.com/v1.0/me/calendars/{$id}/events
strResponse := CkHttp__quickGetStr(http,'https://graph.microsoft.com/v1.0/me/calendars/{$id}/events');
if (CkHttp_getLastMethodSuccess(http) = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
json := CkJsonObject_Create();
CkJsonObject_Load(json,strResponse);
CkJsonObject_putEmitCompact(json,False);
if (CkHttp_getLastStatus(http) <> 200) then
begin
Memo1.Lines.Add(CkJsonObject__emit(json));
Memo1.Lines.Add('Failed, response status code = ' + IntToStr(CkHttp_getLastStatus(http)));
Exit;
end;
Memo1.Lines.Add(CkJsonObject__emit(json));
// Sample output:
// (See parsing code below..)
// {
// "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('admin%40chilkat.io')/calendars('AQMkADAwATM0MDAAMS1i ... AClEpRTgAAAA%3D%3D')/events",
// "value": [
// {
// "@odata.etag": "W/\"5+vF7TKKdE6bGCRqXyl2PQAClIgmmw==\"",
// "id": "AQMkADAwATM0MDAAM ... AApRZ7JkAAAA=",
// "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": "040000008200E ... A230FEBFE5F7486A",
// "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=AQMkADAwATM0MDAAMS1iNTcwLWI2NT ... gkal8pdj0AApRZ7JkAAAA%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-15T20:00:00.0000000",
// "timeZone": "UTC"
// },
// "end": {
// "dateTime": "2019-11-15T22:00:00.0000000",
// "timeZone": "UTC"
// },
// "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
odataContext := CkJsonObject__stringOf(json,'"@odata.context"');
i := 0;
count_i := CkJsonObject_SizeOfArray(json,'value');
while i < count_i do
begin
CkJsonObject_putI(json,i);
odataEtag := CkJsonObject__stringOf(json,'value[i]."@odata.etag"');
id := CkJsonObject__stringOf(json,'value[i].id');
createdDateTime := CkJsonObject__stringOf(json,'value[i].createdDateTime');
lastModifiedDateTime := CkJsonObject__stringOf(json,'value[i].lastModifiedDateTime');
changeKey := CkJsonObject__stringOf(json,'value[i].changeKey');
originalStartTimeZone := CkJsonObject__stringOf(json,'value[i].originalStartTimeZone');
originalEndTimeZone := CkJsonObject__stringOf(json,'value[i].originalEndTimeZone');
iCalUId := CkJsonObject__stringOf(json,'value[i].iCalUId');
reminderMinutesBeforeStart := CkJsonObject_IntOf(json,'value[i].reminderMinutesBeforeStart');
isReminderOn := CkJsonObject_BoolOf(json,'value[i].isReminderOn');
hasAttachments := CkJsonObject_BoolOf(json,'value[i].hasAttachments');
subject := CkJsonObject__stringOf(json,'value[i].subject');
bodyPreview := CkJsonObject__stringOf(json,'value[i].bodyPreview');
importance := CkJsonObject__stringOf(json,'value[i].importance');
sensitivity := CkJsonObject__stringOf(json,'value[i].sensitivity');
isAllDay := CkJsonObject_BoolOf(json,'value[i].isAllDay');
isCancelled := CkJsonObject_BoolOf(json,'value[i].isCancelled');
isOrganizer := CkJsonObject_BoolOf(json,'value[i].isOrganizer');
responseRequested := CkJsonObject_BoolOf(json,'value[i].responseRequested');
seriesMasterId := CkJsonObject__stringOf(json,'value[i].seriesMasterId');
showAs := CkJsonObject__stringOf(json,'value[i].showAs');
v_type := CkJsonObject__stringOf(json,'value[i].type');
webLink := CkJsonObject__stringOf(json,'value[i].webLink');
onlineMeetingUrl := CkJsonObject__stringOf(json,'value[i].onlineMeetingUrl');
recurrence := CkJsonObject__stringOf(json,'value[i].recurrence');
responseStatusResponse := CkJsonObject__stringOf(json,'value[i].responseStatus.response');
responseStatusTime := CkJsonObject__stringOf(json,'value[i].responseStatus.time');
bodyContentType := CkJsonObject__stringOf(json,'value[i].body.contentType');
bodyContent := CkJsonObject__stringOf(json,'value[i].body.content');
startDateTime := CkJsonObject__stringOf(json,'value[i].start.dateTime');
startTimeZone := CkJsonObject__stringOf(json,'value[i].start.timeZone');
endDateTime := CkJsonObject__stringOf(json,'value[i].end.dateTime');
endTimeZone := CkJsonObject__stringOf(json,'value[i].end.timeZone');
locationDisplayName := CkJsonObject__stringOf(json,'value[i].location.displayName');
locationLocationType := CkJsonObject__stringOf(json,'value[i].location.locationType');
locationUniqueId := CkJsonObject__stringOf(json,'value[i].location.uniqueId');
locationUniqueIdType := CkJsonObject__stringOf(json,'value[i].location.uniqueIdType');
organizerEmailAddressName := CkJsonObject__stringOf(json,'value[i].organizer.emailAddress.name');
organizerEmailAddressAddress := CkJsonObject__stringOf(json,'value[i].organizer.emailAddress.address');
j := 0;
count_j := CkJsonObject_SizeOfArray(json,'value[i].categories');
while j < count_j do
begin
CkJsonObject_putJ(json,j);
// ...
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(json,'value[i].locations');
while j < count_j do
begin
CkJsonObject_putJ(json,j);
displayName := CkJsonObject__stringOf(json,'value[i].locations[j].displayName');
locationType := CkJsonObject__stringOf(json,'value[i].locations[j].locationType');
uniqueId := CkJsonObject__stringOf(json,'value[i].locations[j].uniqueId');
uniqueIdType := CkJsonObject__stringOf(json,'value[i].locations[j].uniqueIdType');
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(json,'value[i].attendees');
while j < count_j do
begin
CkJsonObject_putJ(json,j);
v_type := CkJsonObject__stringOf(json,'value[i].attendees[j].type');
statusResponse := CkJsonObject__stringOf(json,'value[i].attendees[j].status.response');
statusTime := CkJsonObject__stringOf(json,'value[i].attendees[j].status.time');
emailAddressName := CkJsonObject__stringOf(json,'value[i].attendees[j].emailAddress.name');
emailAddressAddress := CkJsonObject__stringOf(json,'value[i].attendees[j].emailAddress.address');
j := j + 1;
end;
i := i + 1;
end;
Memo1.Lines.Add('Success.');
CkHttp_Dispose(http);
CkJsonObject_Dispose(jsonToken);
CkJsonObject_Dispose(json);
end;