Unicode C
Unicode C
Outlook List Contacts
See more Outlook Contact Examples
List Outlook ContactsChilkat Unicode C Downloads
#include <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>
void ChilkatSample(void)
{
BOOL success;
HCkHttpW http;
HCkJsonObjectW jsonToken;
HCkStringBuilderW sbJson;
int statusCode;
HCkJsonObjectW jResp;
const wchar_t *odata_etag;
const wchar_t *id;
const wchar_t *createdDateTime;
const wchar_t *lastModifiedDateTime;
const wchar_t *changeKey;
const wchar_t *parentFolderId;
const wchar_t *birthday;
const wchar_t *fileAs;
const wchar_t *displayName;
const wchar_t *givenName;
const wchar_t *initials;
const wchar_t *middleName;
const wchar_t *nickName;
const wchar_t *surname;
const wchar_t *title;
const wchar_t *yomiGivenName;
const wchar_t *yomiSurname;
const wchar_t *yomiCompanyName;
const wchar_t *generation;
const wchar_t *jobTitle;
const wchar_t *companyName;
const wchar_t *department;
const wchar_t *officeLocation;
const wchar_t *profession;
const wchar_t *businessHomePage;
const wchar_t *assistantName;
const wchar_t *manager;
const wchar_t *mobilePhone;
const wchar_t *spouseName;
const wchar_t *personalNotes;
int j;
int count_j;
const wchar_t *strVal;
const wchar_t *name;
const wchar_t *address;
const wchar_t *odata_context;
int i;
int count_i;
success = FALSE;
// 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 here: Get Outlook Contacts OAuth2 Access Token (Azure AD v2.0 Endpoint).
jsonToken = CkJsonObjectW_Create();
success = CkJsonObjectW_LoadFile(jsonToken,L"qa_data/tokens/outlookContacts.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"));
// Send the following GET:
// GET https://graph.microsoft.com/v1.0/me/contacts
sbJson = CkStringBuilderW_Create();
success = CkHttpW_QuickGetSb(http,L"https://graph.microsoft.com/v1.0/me/contacts",sbJson);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkStringBuilderW_Dispose(sbJson);
return;
}
statusCode = CkHttpW_getLastStatus(http);
wprintf(L"Response status code = %d\n",statusCode);
if (statusCode != 200) {
wprintf(L"%s\n",CkStringBuilderW_getAsString(sbJson));
wprintf(L"Failed.\n");
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkStringBuilderW_Dispose(sbJson);
return;
}
jResp = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(jResp,sbJson);
CkJsonObjectW_putEmitCompact(jResp,FALSE);
wprintf(L"%s\n",CkJsonObjectW_emit(jResp));
// Sample output:
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// {
// "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#users('4ee732c3-322e-4a6b-b729-2fd1eb5c6004')/contacts",
// "value": [
// {
// "@odata.etag": "W/\"EQAAABYAAABUcG0qWqkmQYqWLHQataQxAAD0iYfT\"",
// "id": "AAMkADYzZWE3YmZmLWU0YzgtNGNkZC04MGE1LWFiYTFlNTRlY2QwYQBGAAAAAAAu7cUXL5YOTrdsUIw7-v8FBwBUcG0qWqkmQYqWLHQataQxAAAAAAEOAABUcG0qWqkmQYqWLHQataQxAAD0sxexAAA=",
// "createdDateTime": "2021-06-29T16:32:05Z",
// "lastModifiedDateTime": "2021-06-29T16:32:06Z",
// "changeKey": "EQAAABYAAABUcG0qWqkmQYqWLHQataQxAAD0iYfT",
// "categories": [
// ],
// "parentFolderId": "AAMkADYzZWE3YmZmLWU0YzgtNGNkZC04MGE1LWFiYTFlNTRlY2QwYQAuAAAAAAAu7cUXL5YOTrdsUIw7-v8FAQBUcG0qWqkmQYqWLHQataQxAAAAAAEOAAA=",
// "birthday": null,
// "fileAs": "",
// "displayName": "Pavel Bansky",
// "givenName": "Pavel",
// "initials": null,
// "middleName": null,
// "nickName": null,
// "surname": "Bansky",
// "title": null,
// "yomiGivenName": null,
// "yomiSurname": null,
// "yomiCompanyName": null,
// "generation": null,
// "imAddresses": [
// ],
// "jobTitle": null,
// "companyName": null,
// "department": null,
// "officeLocation": null,
// "profession": null,
// "businessHomePage": null,
// "assistantName": null,
// "manager": null,
// "homePhones": [
// ],
// "mobilePhone": null,
// "businessPhones": [
// "+1 732 555 0102"
// ],
// "spouseName": null,
// "personalNotes": "",
// "children": [
// ],
// "emailAddresses": [
// {
// "name": "Pavel Bansky",
// "address": "pavelb@fabrikam.onmicrosoft.com"
// }
// ],
// "homeAddress": {},
// "businessAddress": {},
// "otherAddress": {}
// },
// ...
// ]
// }
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
odata_context = CkJsonObjectW_stringOf(jResp,L"\"@odata.context\"");
i = 0;
count_i = CkJsonObjectW_SizeOfArray(jResp,L"value");
while (i < count_i) {
CkJsonObjectW_putI(jResp,i);
odata_etag = CkJsonObjectW_stringOf(jResp,L"value[i].\"@odata.etag\"");
id = CkJsonObjectW_stringOf(jResp,L"value[i].id");
createdDateTime = CkJsonObjectW_stringOf(jResp,L"value[i].createdDateTime");
lastModifiedDateTime = CkJsonObjectW_stringOf(jResp,L"value[i].lastModifiedDateTime");
changeKey = CkJsonObjectW_stringOf(jResp,L"value[i].changeKey");
parentFolderId = CkJsonObjectW_stringOf(jResp,L"value[i].parentFolderId");
birthday = CkJsonObjectW_stringOf(jResp,L"value[i].birthday");
fileAs = CkJsonObjectW_stringOf(jResp,L"value[i].fileAs");
displayName = CkJsonObjectW_stringOf(jResp,L"value[i].displayName");
givenName = CkJsonObjectW_stringOf(jResp,L"value[i].givenName");
initials = CkJsonObjectW_stringOf(jResp,L"value[i].initials");
middleName = CkJsonObjectW_stringOf(jResp,L"value[i].middleName");
nickName = CkJsonObjectW_stringOf(jResp,L"value[i].nickName");
surname = CkJsonObjectW_stringOf(jResp,L"value[i].surname");
title = CkJsonObjectW_stringOf(jResp,L"value[i].title");
yomiGivenName = CkJsonObjectW_stringOf(jResp,L"value[i].yomiGivenName");
yomiSurname = CkJsonObjectW_stringOf(jResp,L"value[i].yomiSurname");
yomiCompanyName = CkJsonObjectW_stringOf(jResp,L"value[i].yomiCompanyName");
generation = CkJsonObjectW_stringOf(jResp,L"value[i].generation");
jobTitle = CkJsonObjectW_stringOf(jResp,L"value[i].jobTitle");
companyName = CkJsonObjectW_stringOf(jResp,L"value[i].companyName");
department = CkJsonObjectW_stringOf(jResp,L"value[i].department");
officeLocation = CkJsonObjectW_stringOf(jResp,L"value[i].officeLocation");
profession = CkJsonObjectW_stringOf(jResp,L"value[i].profession");
businessHomePage = CkJsonObjectW_stringOf(jResp,L"value[i].businessHomePage");
assistantName = CkJsonObjectW_stringOf(jResp,L"value[i].assistantName");
manager = CkJsonObjectW_stringOf(jResp,L"value[i].manager");
mobilePhone = CkJsonObjectW_stringOf(jResp,L"value[i].mobilePhone");
spouseName = CkJsonObjectW_stringOf(jResp,L"value[i].spouseName");
personalNotes = CkJsonObjectW_stringOf(jResp,L"value[i].personalNotes");
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"value[i].categories");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"value[i].imAddresses");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"value[i].homePhones");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"value[i].businessPhones");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
strVal = CkJsonObjectW_stringOf(jResp,L"value[i].businessPhones[j]");
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"value[i].children");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
j = j + 1;
}
j = 0;
count_j = CkJsonObjectW_SizeOfArray(jResp,L"value[i].emailAddresses");
while (j < count_j) {
CkJsonObjectW_putJ(jResp,j);
name = CkJsonObjectW_stringOf(jResp,L"value[i].emailAddresses[j].name");
address = CkJsonObjectW_stringOf(jResp,L"value[i].emailAddresses[j].address");
j = j + 1;
}
i = i + 1;
}
CkHttpW_Dispose(http);
CkJsonObjectW_Dispose(jsonToken);
CkStringBuilderW_Dispose(sbJson);
CkJsonObjectW_Dispose(jResp);
}