Swift
Swift
Outlook List Contacts
See more Outlook Contact Examples
List Outlook ContactsChilkat Swift Downloads
func chilkatTest() {
var success: Bool = false
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
let http = CkoHttp()!
// Use your previously obtained access token here: Get Outlook Contacts OAuth2 Access Token (Azure AD v2.0 Endpoint).
let jsonToken = CkoJsonObject()!
success = jsonToken.loadFile(path: "qa_data/tokens/outlookContacts.json")
if success == false {
print("\(jsonToken.lastErrorText!)")
return
}
http.authToken = jsonToken.string(of: "access_token")
// Send the following GET:
// GET https://graph.microsoft.com/v1.0/me/contacts
let sbJson = CkoStringBuilder()!
success = http.quickGetSb(url: "https://graph.microsoft.com/v1.0/me/contacts", sbContent: sbJson)
if success == false {
print("\(http.lastErrorText!)")
return
}
var statusCode: Int = http.lastStatus.intValue
print("Response status code = \(statusCode)")
if statusCode != 200 {
print("\(sbJson.getAsString()!)")
print("Failed.")
return
}
let jResp = CkoJsonObject()!
jResp.loadSb(sb: sbJson)
jResp.emitCompact = false
print("\(jResp.emit()!)")
// 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": {}
// },
// ...
// ]
// }
var odata_etag: String?
var id: String?
var createdDateTime: String?
var lastModifiedDateTime: String?
var changeKey: String?
var parentFolderId: String?
var birthday: String?
var fileAs: String?
var displayName: String?
var givenName: String?
var initials: String?
var middleName: String?
var nickName: String?
var surname: String?
var title: String?
var yomiGivenName: String?
var yomiSurname: String?
var yomiCompanyName: String?
var generation: String?
var jobTitle: String?
var companyName: String?
var department: String?
var officeLocation: String?
var profession: String?
var businessHomePage: String?
var assistantName: String?
var manager: String?
var mobilePhone: String?
var spouseName: String?
var personalNotes: String?
var j: Int
var count_j: Int
var strVal: String?
var name: String?
var address: String?
var odata_context: String? = jResp.string(of: "\"@odata.context\"")
var i: Int = 0
var count_i: Int = jResp.size(ofArray: "value").intValue
while i < count_i {
jResp.i = i
odata_etag = jResp.string(of: "value[i].\"@odata.etag\"")
id = jResp.string(of: "value[i].id")
createdDateTime = jResp.string(of: "value[i].createdDateTime")
lastModifiedDateTime = jResp.string(of: "value[i].lastModifiedDateTime")
changeKey = jResp.string(of: "value[i].changeKey")
parentFolderId = jResp.string(of: "value[i].parentFolderId")
birthday = jResp.string(of: "value[i].birthday")
fileAs = jResp.string(of: "value[i].fileAs")
displayName = jResp.string(of: "value[i].displayName")
givenName = jResp.string(of: "value[i].givenName")
initials = jResp.string(of: "value[i].initials")
middleName = jResp.string(of: "value[i].middleName")
nickName = jResp.string(of: "value[i].nickName")
surname = jResp.string(of: "value[i].surname")
title = jResp.string(of: "value[i].title")
yomiGivenName = jResp.string(of: "value[i].yomiGivenName")
yomiSurname = jResp.string(of: "value[i].yomiSurname")
yomiCompanyName = jResp.string(of: "value[i].yomiCompanyName")
generation = jResp.string(of: "value[i].generation")
jobTitle = jResp.string(of: "value[i].jobTitle")
companyName = jResp.string(of: "value[i].companyName")
department = jResp.string(of: "value[i].department")
officeLocation = jResp.string(of: "value[i].officeLocation")
profession = jResp.string(of: "value[i].profession")
businessHomePage = jResp.string(of: "value[i].businessHomePage")
assistantName = jResp.string(of: "value[i].assistantName")
manager = jResp.string(of: "value[i].manager")
mobilePhone = jResp.string(of: "value[i].mobilePhone")
spouseName = jResp.string(of: "value[i].spouseName")
personalNotes = jResp.string(of: "value[i].personalNotes")
j = 0
count_j = jResp.size(ofArray: "value[i].categories").intValue
while j < count_j {
jResp.j = j
j = j + 1
}
j = 0
count_j = jResp.size(ofArray: "value[i].imAddresses").intValue
while j < count_j {
jResp.j = j
j = j + 1
}
j = 0
count_j = jResp.size(ofArray: "value[i].homePhones").intValue
while j < count_j {
jResp.j = j
j = j + 1
}
j = 0
count_j = jResp.size(ofArray: "value[i].businessPhones").intValue
while j < count_j {
jResp.j = j
strVal = jResp.string(of: "value[i].businessPhones[j]")
j = j + 1
}
j = 0
count_j = jResp.size(ofArray: "value[i].children").intValue
while j < count_j {
jResp.j = j
j = j + 1
}
j = 0
count_j = jResp.size(ofArray: "value[i].emailAddresses").intValue
while j < count_j {
jResp.j = j
name = jResp.string(of: "value[i].emailAddresses[j].name")
address = jResp.string(of: "value[i].emailAddresses[j].address")
j = j + 1
}
i = i + 1
}
}