Delphi DLL
Delphi DLL
Outlook List Contacts
See more Outlook Contact Examples
List Outlook ContactsChilkat Delphi DLL Downloads
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, JsonObject;
...
procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
jsonToken: HCkJsonObject;
sbJson: HCkStringBuilder;
statusCode: Integer;
jResp: HCkJsonObject;
odata_etag: PWideChar;
id: PWideChar;
createdDateTime: PWideChar;
lastModifiedDateTime: PWideChar;
changeKey: PWideChar;
parentFolderId: PWideChar;
birthday: PWideChar;
fileAs: PWideChar;
displayName: PWideChar;
givenName: PWideChar;
initials: PWideChar;
middleName: PWideChar;
nickName: PWideChar;
surname: PWideChar;
title: PWideChar;
yomiGivenName: PWideChar;
yomiSurname: PWideChar;
yomiCompanyName: PWideChar;
generation: PWideChar;
jobTitle: PWideChar;
companyName: PWideChar;
department: PWideChar;
officeLocation: PWideChar;
profession: PWideChar;
businessHomePage: PWideChar;
assistantName: PWideChar;
manager: PWideChar;
mobilePhone: PWideChar;
spouseName: PWideChar;
personalNotes: PWideChar;
j: Integer;
count_j: Integer;
strVal: PWideChar;
name: PWideChar;
address: PWideChar;
odata_context: PWideChar;
i: Integer;
count_i: Integer;
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 here: Get Outlook Contacts OAuth2 Access Token (Azure AD v2.0 Endpoint).
jsonToken := CkJsonObject_Create();
success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/outlookContacts.json');
if (success = False) then
begin
Memo1.Lines.Add(CkJsonObject__lastErrorText(jsonToken));
Exit;
end;
CkHttp_putAuthToken(http,CkJsonObject__stringOf(jsonToken,'access_token'));
// Send the following GET:
// GET https://graph.microsoft.com/v1.0/me/contacts
sbJson := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,'https://graph.microsoft.com/v1.0/me/contacts',sbJson);
if (success = False) then
begin
Memo1.Lines.Add(CkHttp__lastErrorText(http));
Exit;
end;
statusCode := CkHttp_getLastStatus(http);
Memo1.Lines.Add('Response status code = ' + IntToStr(statusCode));
if (statusCode <> 200) then
begin
Memo1.Lines.Add(CkStringBuilder__getAsString(sbJson));
Memo1.Lines.Add('Failed.');
Exit;
end;
jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbJson);
CkJsonObject_putEmitCompact(jResp,False);
Memo1.Lines.Add(CkJsonObject__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": {}
// },
// ...
// ]
// }
odata_context := CkJsonObject__stringOf(jResp,'"@odata.context"');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'value');
while i < count_i do
begin
CkJsonObject_putI(jResp,i);
odata_etag := CkJsonObject__stringOf(jResp,'value[i]."@odata.etag"');
id := CkJsonObject__stringOf(jResp,'value[i].id');
createdDateTime := CkJsonObject__stringOf(jResp,'value[i].createdDateTime');
lastModifiedDateTime := CkJsonObject__stringOf(jResp,'value[i].lastModifiedDateTime');
changeKey := CkJsonObject__stringOf(jResp,'value[i].changeKey');
parentFolderId := CkJsonObject__stringOf(jResp,'value[i].parentFolderId');
birthday := CkJsonObject__stringOf(jResp,'value[i].birthday');
fileAs := CkJsonObject__stringOf(jResp,'value[i].fileAs');
displayName := CkJsonObject__stringOf(jResp,'value[i].displayName');
givenName := CkJsonObject__stringOf(jResp,'value[i].givenName');
initials := CkJsonObject__stringOf(jResp,'value[i].initials');
middleName := CkJsonObject__stringOf(jResp,'value[i].middleName');
nickName := CkJsonObject__stringOf(jResp,'value[i].nickName');
surname := CkJsonObject__stringOf(jResp,'value[i].surname');
title := CkJsonObject__stringOf(jResp,'value[i].title');
yomiGivenName := CkJsonObject__stringOf(jResp,'value[i].yomiGivenName');
yomiSurname := CkJsonObject__stringOf(jResp,'value[i].yomiSurname');
yomiCompanyName := CkJsonObject__stringOf(jResp,'value[i].yomiCompanyName');
generation := CkJsonObject__stringOf(jResp,'value[i].generation');
jobTitle := CkJsonObject__stringOf(jResp,'value[i].jobTitle');
companyName := CkJsonObject__stringOf(jResp,'value[i].companyName');
department := CkJsonObject__stringOf(jResp,'value[i].department');
officeLocation := CkJsonObject__stringOf(jResp,'value[i].officeLocation');
profession := CkJsonObject__stringOf(jResp,'value[i].profession');
businessHomePage := CkJsonObject__stringOf(jResp,'value[i].businessHomePage');
assistantName := CkJsonObject__stringOf(jResp,'value[i].assistantName');
manager := CkJsonObject__stringOf(jResp,'value[i].manager');
mobilePhone := CkJsonObject__stringOf(jResp,'value[i].mobilePhone');
spouseName := CkJsonObject__stringOf(jResp,'value[i].spouseName');
personalNotes := CkJsonObject__stringOf(jResp,'value[i].personalNotes');
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'value[i].categories');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'value[i].imAddresses');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'value[i].homePhones');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'value[i].businessPhones');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
strVal := CkJsonObject__stringOf(jResp,'value[i].businessPhones[j]');
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'value[i].children');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
j := j + 1;
end;
j := 0;
count_j := CkJsonObject_SizeOfArray(jResp,'value[i].emailAddresses');
while j < count_j do
begin
CkJsonObject_putJ(jResp,j);
name := CkJsonObject__stringOf(jResp,'value[i].emailAddresses[j].name');
address := CkJsonObject__stringOf(jResp,'value[i].emailAddresses[j].address');
j := j + 1;
end;
i := i + 1;
end;
CkHttp_Dispose(http);
CkJsonObject_Dispose(jsonToken);
CkStringBuilder_Dispose(sbJson);
CkJsonObject_Dispose(jResp);
end;