Rust
Rust
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 Rust Downloads
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = chilkat::Http::new();
// Use your previously obtained access token as shown here:
// Get Microsoft Graph OAuth2 Access Token with Calendars.ReadWrite scope.
let json_token = chilkat::JsonObject::new();
if json_token.load_file("qa_data/tokens/msGraphCalendar.json").is_err() {
println!("{}", json_token.last_error_text());
return;
}
http.set_auth_token(&json_token.string_of("access_token").unwrap_or_default());
// Specify the calendar id
let _ = http.set_url_var("id", "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAClEpRTgAAAA==");
// Send a GET request to https://graph.microsoft.com/v1.0/me/calendars/{$id}/events
let Ok(str_response) = http.quick_get_str("https://graph.microsoft.com/v1.0/me/calendars/{$id}/events") else {
println!("{}", http.last_error_text());
return;
};
let json = chilkat::JsonObject::new();
let _ = json.load(&str_response);
json.set_emit_compact(false);
if http.last_status() != 200 {
println!("{}", json.emit().unwrap_or_default());
println!("Failed, response status code = {}", http.last_status());
return;
}
println!("{}", json.emit().unwrap_or_default());
// 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
let mut i: i32 = 0;
let mut j: i32 = 0;
let mut count_j: i32 = 0;
let odata_context = json.string_of("\"@odata.context\"").unwrap_or_default();
i = 0;
let count_i = json.size_of_array("value");
while i < count_i {
json.set_i(i);
let _ = json.string_of("value[i].\"@odata.etag\"").unwrap_or_default();
let _ = json.string_of("value[i].id").unwrap_or_default();
let _ = json.string_of("value[i].createdDateTime").unwrap_or_default();
let _ = json.string_of("value[i].lastModifiedDateTime").unwrap_or_default();
let _ = json.string_of("value[i].changeKey").unwrap_or_default();
let _ = json.string_of("value[i].originalStartTimeZone").unwrap_or_default();
let _ = json.string_of("value[i].originalEndTimeZone").unwrap_or_default();
let _ = json.string_of("value[i].iCalUId").unwrap_or_default();
let _ = json.int_of("value[i].reminderMinutesBeforeStart");
let _ = json.bool_of("value[i].isReminderOn");
let _ = json.bool_of("value[i].hasAttachments");
let _ = json.string_of("value[i].subject").unwrap_or_default();
let _ = json.string_of("value[i].bodyPreview").unwrap_or_default();
let _ = json.string_of("value[i].importance").unwrap_or_default();
let _ = json.string_of("value[i].sensitivity").unwrap_or_default();
let _ = json.bool_of("value[i].isAllDay");
let _ = json.bool_of("value[i].isCancelled");
let _ = json.bool_of("value[i].isOrganizer");
let _ = json.bool_of("value[i].responseRequested");
let _ = json.string_of("value[i].seriesMasterId").unwrap_or_default();
let _ = json.string_of("value[i].showAs").unwrap_or_default();
let _ = json.string_of("value[i].type").unwrap_or_default();
let _ = json.string_of("value[i].webLink").unwrap_or_default();
let _ = json.string_of("value[i].onlineMeetingUrl").unwrap_or_default();
let _ = json.string_of("value[i].recurrence").unwrap_or_default();
let _ = json.string_of("value[i].responseStatus.response").unwrap_or_default();
let _ = json.string_of("value[i].responseStatus.time").unwrap_or_default();
let _ = json.string_of("value[i].body.contentType").unwrap_or_default();
let _ = json.string_of("value[i].body.content").unwrap_or_default();
let _ = json.string_of("value[i].start.dateTime").unwrap_or_default();
let _ = json.string_of("value[i].start.timeZone").unwrap_or_default();
let _ = json.string_of("value[i].end.dateTime").unwrap_or_default();
let _ = json.string_of("value[i].end.timeZone").unwrap_or_default();
let _ = json.string_of("value[i].location.displayName").unwrap_or_default();
let _ = json.string_of("value[i].location.locationType").unwrap_or_default();
let _ = json.string_of("value[i].location.uniqueId").unwrap_or_default();
let _ = json.string_of("value[i].location.uniqueIdType").unwrap_or_default();
let _ = json.string_of("value[i].organizer.emailAddress.name").unwrap_or_default();
let _ = json.string_of("value[i].organizer.emailAddress.address").unwrap_or_default();
j = 0;
count_j = json.size_of_array("value[i].categories");
while j < count_j {
json.set_j(j);
// ...
j = j + 1;
}
j = 0;
count_j = json.size_of_array("value[i].locations");
while j < count_j {
json.set_j(j);
let _ = json.string_of("value[i].locations[j].displayName").unwrap_or_default();
let _ = json.string_of("value[i].locations[j].locationType").unwrap_or_default();
let _ = json.string_of("value[i].locations[j].uniqueId").unwrap_or_default();
let _ = json.string_of("value[i].locations[j].uniqueIdType").unwrap_or_default();
j = j + 1;
}
j = 0;
count_j = json.size_of_array("value[i].attendees");
while j < count_j {
json.set_j(j);
let _ = json.string_of("value[i].attendees[j].type").unwrap_or_default();
let _ = json.string_of("value[i].attendees[j].status.response").unwrap_or_default();
let _ = json.string_of("value[i].attendees[j].status.time").unwrap_or_default();
let _ = json.string_of("value[i].attendees[j].emailAddress.name").unwrap_or_default();
let _ = json.string_of("value[i].attendees[j].emailAddress.address").unwrap_or_default();
j = j + 1;
}
i = i + 1;
}
println!("Success.");