Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) Google People API - List the User's ContactsGets a list of people in the user's contacts. For more information, see https://developers.google.com/people/v1/contacts
IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; 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 jsonToken.i = CkJsonObject::ckCreate() If jsonToken.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/googlePeople.json") If success <> 1 Debug "Failed to load googleContacts.json" CkJsonObject::ckDispose(jsonToken) ProcedureReturn EndIf http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttp::setCkAuthToken(http, CkJsonObject::ckStringOf(jsonToken,"access_token")) sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success = CkHttp::ckQuickGetSb(http,"https://people.googleapis.com/v1/people/me/connections?personFields=names,addresses,emailAddresses",sbResponseBody) If success = 0 Debug CkHttp::ckLastErrorText(http) Debug CkStringBuilder::ckGetAsString(sbResponseBody) CkJsonObject::ckDispose(jsonToken) CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) ProcedureReturn EndIf ; 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 ; } json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::setCkEmitCompact(json, 0) CkJsonObject::ckLoad(json,CkStringBuilder::ckGetAsString(sbResponseBody)) Debug CkJsonObject::ckEmit(json) resourceName.s etag.s j.i count_j.i metadataPrimary.i metadataSourceType.s metadataSourceId.s displayName.s familyName.s givenName.s displayNameLastFirst.s unstructuredName.s value.s formattedValue.s streetAddress.s city.s region.s postalCode.s country.s countryCode.s totalPeople.i = CkJsonObject::ckIntOf(json,"totalPeople") totalItems.i = CkJsonObject::ckIntOf(json,"totalItems") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(json,"connections") While i < count_i CkJsonObject::setCkI(json, i) resourceName = CkJsonObject::ckStringOf(json,"connections[i].resourceName") etag = CkJsonObject::ckStringOf(json,"connections[i].etag") j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"connections[i].names") While j < count_j CkJsonObject::setCkJ(json, j) metadataPrimary = CkJsonObject::ckBoolOf(json,"connections[i].names[j].metadata.primary") metadataSourceType = CkJsonObject::ckStringOf(json,"connections[i].names[j].metadata.source.type") metadataSourceId = CkJsonObject::ckStringOf(json,"connections[i].names[j].metadata.source.id") displayName = CkJsonObject::ckStringOf(json,"connections[i].names[j].displayName") familyName = CkJsonObject::ckStringOf(json,"connections[i].names[j].familyName") givenName = CkJsonObject::ckStringOf(json,"connections[i].names[j].givenName") displayNameLastFirst = CkJsonObject::ckStringOf(json,"connections[i].names[j].displayNameLastFirst") unstructuredName = CkJsonObject::ckStringOf(json,"connections[i].names[j].unstructuredName") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"connections[i].emailAddresses") While j < count_j CkJsonObject::setCkJ(json, j) metadataPrimary = CkJsonObject::ckBoolOf(json,"connections[i].emailAddresses[j].metadata.primary") metadataSourceType = CkJsonObject::ckStringOf(json,"connections[i].emailAddresses[j].metadata.source.type") metadataSourceId = CkJsonObject::ckStringOf(json,"connections[i].emailAddresses[j].metadata.source.id") value = CkJsonObject::ckStringOf(json,"connections[i].emailAddresses[j].value") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(json,"connections[i].addresses") While j < count_j CkJsonObject::setCkJ(json, j) metadataPrimary = CkJsonObject::ckBoolOf(json,"connections[i].addresses[j].metadata.primary") metadataSourceType = CkJsonObject::ckStringOf(json,"connections[i].addresses[j].metadata.source.type") metadataSourceId = CkJsonObject::ckStringOf(json,"connections[i].addresses[j].metadata.source.id") formattedValue = CkJsonObject::ckStringOf(json,"connections[i].addresses[j].formattedValue") streetAddress = CkJsonObject::ckStringOf(json,"connections[i].addresses[j].streetAddress") city = CkJsonObject::ckStringOf(json,"connections[i].addresses[j].city") region = CkJsonObject::ckStringOf(json,"connections[i].addresses[j].region") postalCode = CkJsonObject::ckStringOf(json,"connections[i].addresses[j].postalCode") country = CkJsonObject::ckStringOf(json,"connections[i].addresses[j].country") countryCode = CkJsonObject::ckStringOf(json,"connections[i].addresses[j].countryCode") j = j + 1 Wend i = i + 1 Wend CkJsonObject::ckDispose(jsonToken) CkHttp::ckDispose(http) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(json) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.