Sample code for 30+ languages & platforms
PowerBuilder

Google People API - List the User's Contacts

See more Google People Examples

Gets a list of people in the user's contacts.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_JsonToken
oleobject loo_Http
oleobject loo_SbResponseBody
oleobject loo_Json
string ls_ResourceName
string ls_Etag
integer j
integer li_Count_j
integer li_MetadataPrimary
string ls_MetadataSourceType
string ls_MetadataSourceId
string ls_DisplayName
string ls_FamilyName
string ls_GivenName
string ls_DisplayNameLastFirst
string ls_UnstructuredName
string ls_Value
string ls_FormattedValue
string ls_StreetAddress
string ls_City
string ls_Region
string ls_PostalCode
string ls_Country
string ls_CountryCode
integer li_TotalPeople
integer li_TotalItems
integer i
integer li_Count_i

li_Success = 0

// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.

// It is assumed we previously obtained an OAuth2 access token.
// This example loads the JSON access token file 

// originally obtained by this example: Get Google People API OAuth2 Access Token
// or refreshed by this example: Refresh Google People API OAuth2 Access Token

loo_JsonToken = create oleobject
li_rc = loo_JsonToken.ConnectToNewObject("Chilkat.JsonObject")
if li_rc < 0 then
    destroy loo_JsonToken
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_JsonToken.LoadFile("qa_data/tokens/googlePeople.json")
if li_Success <> 1 then
    Write-Debug "Failed to load googleContacts.json"
    destroy loo_JsonToken
    return
end if

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")

loo_Http.AuthToken = loo_JsonToken.StringOf("access_token")

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

li_Success = loo_Http.QuickGetSb("https://people.googleapis.com/v1/people/me/connections?personFields=names,addresses,emailAddresses",loo_SbResponseBody)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    Write-Debug loo_SbResponseBody.GetAsString()
    destroy loo_JsonToken
    destroy loo_Http
    destroy loo_SbResponseBody
    return
end if

// Sample JSON Response

// Use this online tool to generate parsing code from sample JSON: 
// Generate Parsing Code from JSON

// {
//   "connections": [
//     {
//       "resourceName": "people/c8871101035606120608",
//       "etag": "%EgkBAj0JQhBANy4aBAECBQciDERLSGdVTFNPbzNJPQ==",
//       "names": [
//         {
//           "metadata": {
//             "primary": true,
//             "source": {
//               "type": "CONTACT",
//               "id": "7b1c7b6409e718a0"
//             }
//           },
//           "displayName": "Chilkat Cloud",
//           "familyName": "Cloud",
//           "givenName": "Chilkat",
//           "displayNameLastFirst": "Cloud, Chilkat",
//           "unstructuredName": "Chilkat Cloud"
//         }
//       ],
//       "emailAddresses": [
//         {
//           "metadata": {
//             "primary": true,
//             "source": {
//               "type": "CONTACT",
//               "id": "7b1c7b6409e718a0"
//             }
//           },
//           "value": "support@***.com"
//         }
//       ]
//     },
//     {
//       "resourceName": "people/c7607335470312011517",
//       "etag": "%EgkBAj0JQhBANy4aBAECBQciDGZETUtHVTVMazI4PQ==",
//       "names": [
//         {
//           "metadata": {
//             "primary": true,
//             "source": {
//               "type": "CONTACT",
//               "id": "6992af4e0b2d36fd"
//             }
//           },
//           "displayName": "Matt Smith",
//           "familyName": "Smith",
//           "givenName": "Matt",
//           "displayNameLastFirst": "Smith, Matt",
//           "unstructuredName": "Matt Smith"
//         }
//       ],
//       "addresses": [
//         {
//           "metadata": {
//             "primary": true,
//             "source": {
//               "type": "CONTACT",
//               "id": "6992af4e0b2d36fd"
//             }
//           },
//           "formattedValue": "2222 E Foorest Ave\nWheaton, IL 60999\nUS",
//           "streetAddress": "2222 E Foorest Ave",
//           "city": "Wheaton",
//           "region": "IL",
//           "postalCode": "60999",
//           "country": "US",
//           "countryCode": "US"
//         }
//       ],
//       "emailAddresses": [
//         {
//           "metadata": {
//             "primary": true,
//             "source": {
//               "type": "CONTACT",
//               "id": "6992af4e0b2d36fd"
//             }
//           },
//           "value": "matt@***.com"
//         },
//         {
//           "metadata": {
//             "source": {
//               "type": "CONTACT",
//               "id": "6992af4e0b2d36fd"
//             }
//           },
//           "value": "admin@***.com"
//         }
//       ]
//     }
//   ],
//   "totalPeople": 2,
//   "totalItems": 2
// }

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

loo_Json.EmitCompact = 0
loo_Json.Load(loo_SbResponseBody.GetAsString())
Write-Debug loo_Json.Emit()

li_TotalPeople = loo_Json.IntOf("totalPeople")
li_TotalItems = loo_Json.IntOf("totalItems")
i = 0
li_Count_i = loo_Json.SizeOfArray("connections")
do while i < li_Count_i
    loo_Json.I = i
    ls_ResourceName = loo_Json.StringOf("connections[i].resourceName")
    ls_Etag = loo_Json.StringOf("connections[i].etag")
    j = 0
    li_Count_j = loo_Json.SizeOfArray("connections[i].names")
    do while j < li_Count_j
        loo_Json.J = j
        li_MetadataPrimary = loo_Json.BoolOf("connections[i].names[j].metadata.primary")
        ls_MetadataSourceType = loo_Json.StringOf("connections[i].names[j].metadata.source.type")
        ls_MetadataSourceId = loo_Json.StringOf("connections[i].names[j].metadata.source.id")
        ls_DisplayName = loo_Json.StringOf("connections[i].names[j].displayName")
        ls_FamilyName = loo_Json.StringOf("connections[i].names[j].familyName")
        ls_GivenName = loo_Json.StringOf("connections[i].names[j].givenName")
        ls_DisplayNameLastFirst = loo_Json.StringOf("connections[i].names[j].displayNameLastFirst")
        ls_UnstructuredName = loo_Json.StringOf("connections[i].names[j].unstructuredName")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("connections[i].emailAddresses")
    do while j < li_Count_j
        loo_Json.J = j
        li_MetadataPrimary = loo_Json.BoolOf("connections[i].emailAddresses[j].metadata.primary")
        ls_MetadataSourceType = loo_Json.StringOf("connections[i].emailAddresses[j].metadata.source.type")
        ls_MetadataSourceId = loo_Json.StringOf("connections[i].emailAddresses[j].metadata.source.id")
        ls_Value = loo_Json.StringOf("connections[i].emailAddresses[j].value")
        j = j + 1
    loop
    j = 0
    li_Count_j = loo_Json.SizeOfArray("connections[i].addresses")
    do while j < li_Count_j
        loo_Json.J = j
        li_MetadataPrimary = loo_Json.BoolOf("connections[i].addresses[j].metadata.primary")
        ls_MetadataSourceType = loo_Json.StringOf("connections[i].addresses[j].metadata.source.type")
        ls_MetadataSourceId = loo_Json.StringOf("connections[i].addresses[j].metadata.source.id")
        ls_FormattedValue = loo_Json.StringOf("connections[i].addresses[j].formattedValue")
        ls_StreetAddress = loo_Json.StringOf("connections[i].addresses[j].streetAddress")
        ls_City = loo_Json.StringOf("connections[i].addresses[j].city")
        ls_Region = loo_Json.StringOf("connections[i].addresses[j].region")
        ls_PostalCode = loo_Json.StringOf("connections[i].addresses[j].postalCode")
        ls_Country = loo_Json.StringOf("connections[i].addresses[j].country")
        ls_CountryCode = loo_Json.StringOf("connections[i].addresses[j].countryCode")
        j = j + 1
    loop
    i = i + 1
loop


destroy loo_JsonToken
destroy loo_Http
destroy loo_SbResponseBody
destroy loo_Json