Zig
Zig
Outlook Calendar List Events
See more Outlook Calendar Examples
Retrieve a list of events in a calendar.Chilkat Zig Downloads
const std = @import("std");
const chilkat = @import("chilkat");
pub fn main(init: std.process.Init) !void {
const alloc = init.arena.allocator();
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
const http = try chilkat.Http.init();
defer http.deinit();
// Use your previously obtained access token here: Get Outlook Calendar OAuth2 Access Token (Azure AD v2.0 Endpoint).
const json_token = try chilkat.JsonObject.init();
defer json_token.deinit();
json_token.loadFile("qa_data/tokens/outlookCalendar.json") catch {
std.debug.print("{s}\n", .{try json_token.getLastErrorText(alloc)});
return;
};
http.setAuthToken(try json_token.stringOf(alloc, "access_token"));
// Specify the ID of the calendar to list.
const calendar_id = "AQMkADAwATM0MDAAMS1iNTcwLWI2NTEtMDACLTAwCgBGAAADsVyfxjDU406Ic4X7ill8xAcA5_vF7TKKdE6bGCRqXyl2PQAAAgEGAAAA5_vF7TKKdE6bGCRqXyl2PQAAAiCsAAAA";
http.setUrlVar("id", calendar_id) catch {};
// To list the events in the default calendar, use the following URL: https://graph.microsoft.com/v1.0/me/calendars/events
const resp = try chilkat.HttpResponse.init();
defer resp.deinit();
http.httpNoBody("GET", "https://graph.microsoft.com/v1.0/me/calendars/{$id}/events", resp) catch {
std.debug.print("{s}\n", .{try http.getLastErrorText(alloc)});
return;
};
std.debug.print("Response status code = {d}\n", .{resp.getStatusCode()});
// The HTTP request succeeded if the response status code = 200.
if (resp.getStatusCode() != 200) {
std.debug.print("{s}\n", .{try resp.getBodyStr(alloc)});
std.debug.print("Failed\n", .{});
return;
}
const json = try chilkat.JsonObject.init();
defer json.deinit();
json.load(try resp.getBodyStr(alloc)) catch {};
json.setEmitCompact(false);
std.debug.print("{s}\n", .{try json.emit(alloc)});
// Here is a sample response:
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "value": [
// {
// "originalStartTimeZone": "originalStartTimeZone-value",
// "originalEndTimeZone": "originalEndTimeZone-value",
// "responseStatus": {
// "response": "",
// "time": "datetime-value"
// },
// "iCalUId": "iCalUId-value",
// "reminderMinutesBeforeStart": 99,
// "isReminderOn": true
// }
// ]
// }
var original_start_time_zone: [:0]const u8 = "";
var original_end_time_zone: [:0]const u8 = "";
var response_status_response: [:0]const u8 = "";
var response_status_time: [:0]const u8 = "";
var i_cal_u_id: [:0]const u8 = "";
var reminder_minutes_before_start: i32 = 0;
var is_reminder_on: bool = false;
var i: i32 = 0;
const count_i = json.sizeOfArray("value");
while (i < count_i) {
json.setI(i);
original_start_time_zone = try json.stringOf(alloc, "value[i].originalStartTimeZone");
original_end_time_zone = try json.stringOf(alloc, "value[i].originalEndTimeZone");
response_status_response = try json.stringOf(alloc, "value[i].responseStatus.response");
response_status_time = try json.stringOf(alloc, "value[i].responseStatus.time");
i_cal_u_id = try json.stringOf(alloc, "value[i].iCalUId");
reminder_minutes_before_start = json.intOf("value[i].reminderMinutesBeforeStart");
is_reminder_on = json.boolOf("value[i].isReminderOn");
i = i + 1;
}
}