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
(Visual FoxPro) 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
LOCAL loJsonToken LOCAL lnSuccess LOCAL loHttp LOCAL loSbResponseBody LOCAL loJson LOCAL lcResourceName LOCAL lcEtag LOCAL j LOCAL lnCount_j LOCAL lnMetadataPrimary LOCAL lcMetadataSourceType LOCAL lcMetadataSourceId LOCAL lcDisplayName LOCAL lcFamilyName LOCAL lcGivenName LOCAL lcDisplayNameLastFirst LOCAL lcUnstructuredName LOCAL lcValue LOCAL lcFormattedValue LOCAL lcStreetAddress LOCAL lcCity LOCAL lcRegion LOCAL lcPostalCode LOCAL lcCountry LOCAL lcCountryCode LOCAL lnTotalPeople LOCAL lnTotalItems LOCAL i LOCAL lnCount_i * 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 * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJsonToken = CreateObject('Chilkat.JsonObject') lnSuccess = loJsonToken.LoadFile("qa_data/tokens/googlePeople.json") IF (lnSuccess <> 1) THEN ? "Failed to load googleContacts.json" RELEASE loJsonToken CANCEL ENDIF * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.Http') loHttp = CreateObject('Chilkat.Http') loHttp.AuthToken = loJsonToken.StringOf("access_token") * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.StringBuilder') loSbResponseBody = CreateObject('Chilkat.StringBuilder') lnSuccess = loHttp.QuickGetSb("https://people.googleapis.com/v1/people/me/connections?personFields=names,addresses,emailAddresses",loSbResponseBody) IF (lnSuccess = 0) THEN ? loHttp.LastErrorText ? loSbResponseBody.GetAsString() RELEASE loJsonToken RELEASE loHttp RELEASE loSbResponseBody CANCEL 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 * } * For versions of Chilkat < 10.0.0, use CreateObject('Chilkat_9_5_0.JsonObject') loJson = CreateObject('Chilkat.JsonObject') loJson.EmitCompact = 0 loJson.Load(loSbResponseBody.GetAsString()) ? loJson.Emit() lnTotalPeople = loJson.IntOf("totalPeople") lnTotalItems = loJson.IntOf("totalItems") i = 0 lnCount_i = loJson.SizeOfArray("connections") DO WHILE i < lnCount_i loJson.I = i lcResourceName = loJson.StringOf("connections[i].resourceName") lcEtag = loJson.StringOf("connections[i].etag") j = 0 lnCount_j = loJson.SizeOfArray("connections[i].names") DO WHILE j < lnCount_j loJson.J = j lnMetadataPrimary = loJson.BoolOf("connections[i].names[j].metadata.primary") lcMetadataSourceType = loJson.StringOf("connections[i].names[j].metadata.source.type") lcMetadataSourceId = loJson.StringOf("connections[i].names[j].metadata.source.id") lcDisplayName = loJson.StringOf("connections[i].names[j].displayName") lcFamilyName = loJson.StringOf("connections[i].names[j].familyName") lcGivenName = loJson.StringOf("connections[i].names[j].givenName") lcDisplayNameLastFirst = loJson.StringOf("connections[i].names[j].displayNameLastFirst") lcUnstructuredName = loJson.StringOf("connections[i].names[j].unstructuredName") j = j + 1 ENDDO j = 0 lnCount_j = loJson.SizeOfArray("connections[i].emailAddresses") DO WHILE j < lnCount_j loJson.J = j lnMetadataPrimary = loJson.BoolOf("connections[i].emailAddresses[j].metadata.primary") lcMetadataSourceType = loJson.StringOf("connections[i].emailAddresses[j].metadata.source.type") lcMetadataSourceId = loJson.StringOf("connections[i].emailAddresses[j].metadata.source.id") lcValue = loJson.StringOf("connections[i].emailAddresses[j].value") j = j + 1 ENDDO j = 0 lnCount_j = loJson.SizeOfArray("connections[i].addresses") DO WHILE j < lnCount_j loJson.J = j lnMetadataPrimary = loJson.BoolOf("connections[i].addresses[j].metadata.primary") lcMetadataSourceType = loJson.StringOf("connections[i].addresses[j].metadata.source.type") lcMetadataSourceId = loJson.StringOf("connections[i].addresses[j].metadata.source.id") lcFormattedValue = loJson.StringOf("connections[i].addresses[j].formattedValue") lcStreetAddress = loJson.StringOf("connections[i].addresses[j].streetAddress") lcCity = loJson.StringOf("connections[i].addresses[j].city") lcRegion = loJson.StringOf("connections[i].addresses[j].region") lcPostalCode = loJson.StringOf("connections[i].addresses[j].postalCode") lcCountry = loJson.StringOf("connections[i].addresses[j].country") lcCountryCode = loJson.StringOf("connections[i].addresses[j].countryCode") j = j + 1 ENDDO i = i + 1 ENDDO RELEASE loJsonToken RELEASE loHttp RELEASE loSbResponseBody RELEASE loJson |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.