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
(AutoIt) 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
; 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 $oJsonToken = ObjCreate("Chilkat.JsonObject") Local $bSuccess = $oJsonToken.LoadFile("qa_data/tokens/googlePeople.json") If ($bSuccess <> True) Then ConsoleWrite("Failed to load googleContacts.json" & @CRLF) Exit EndIf $oHttp = ObjCreate("Chilkat.Http") $oHttp.AuthToken = $oJsonToken.StringOf("access_token") $oSbResponseBody = ObjCreate("Chilkat.StringBuilder") $bSuccess = $oHttp.QuickGetSb("https://people.googleapis.com/v1/people/me/connections?personFields=names,addresses,emailAddresses",$oSbResponseBody) If ($bSuccess = False) Then ConsoleWrite($oHttp.LastErrorText & @CRLF) ConsoleWrite($oSbResponseBody.GetAsString() & @CRLF) Exit 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 ; } $oJson = ObjCreate("Chilkat.JsonObject") $oJson.EmitCompact = False $oJson.Load($oSbResponseBody.GetAsString()) ConsoleWrite($oJson.Emit() & @CRLF) Local $sResourceName Local $sEtag Local $iJ Local $iCount_j Local $bMetadataPrimary Local $sMetadataSourceType Local $sMetadataSourceId Local $sDisplayName Local $sFamilyName Local $sGivenName Local $sDisplayNameLastFirst Local $sUnstructuredName Local $sValue Local $sFormattedValue Local $streetAddress Local $sCity Local $sRegion Local $sPostalCode Local $sCountry Local $sCountryCode Local $iTotalPeople = $oJson.IntOf("totalPeople") Local $iTotalItems = $oJson.IntOf("totalItems") Local $i = 0 Local $iCount_i = $oJson.SizeOfArray("connections") While $i < $iCount_i $oJson.I = $i $sResourceName = $oJson.StringOf("connections[i].resourceName") $sEtag = $oJson.StringOf("connections[i].etag") $iJ = 0 $iCount_j = $oJson.SizeOfArray("connections[i].names") While $iJ < $iCount_j $oJson.J = $iJ $bMetadataPrimary = $oJson.BoolOf("connections[i].names[j].metadata.primary") $sMetadataSourceType = $oJson.StringOf("connections[i].names[j].metadata.source.type") $sMetadataSourceId = $oJson.StringOf("connections[i].names[j].metadata.source.id") $sDisplayName = $oJson.StringOf("connections[i].names[j].displayName") $sFamilyName = $oJson.StringOf("connections[i].names[j].familyName") $sGivenName = $oJson.StringOf("connections[i].names[j].givenName") $sDisplayNameLastFirst = $oJson.StringOf("connections[i].names[j].displayNameLastFirst") $sUnstructuredName = $oJson.StringOf("connections[i].names[j].unstructuredName") $iJ = $iJ + 1 Wend $iJ = 0 $iCount_j = $oJson.SizeOfArray("connections[i].emailAddresses") While $iJ < $iCount_j $oJson.J = $iJ $bMetadataPrimary = $oJson.BoolOf("connections[i].emailAddresses[j].metadata.primary") $sMetadataSourceType = $oJson.StringOf("connections[i].emailAddresses[j].metadata.source.type") $sMetadataSourceId = $oJson.StringOf("connections[i].emailAddresses[j].metadata.source.id") $sValue = $oJson.StringOf("connections[i].emailAddresses[j].value") $iJ = $iJ + 1 Wend $iJ = 0 $iCount_j = $oJson.SizeOfArray("connections[i].addresses") While $iJ < $iCount_j $oJson.J = $iJ $bMetadataPrimary = $oJson.BoolOf("connections[i].addresses[j].metadata.primary") $sMetadataSourceType = $oJson.StringOf("connections[i].addresses[j].metadata.source.type") $sMetadataSourceId = $oJson.StringOf("connections[i].addresses[j].metadata.source.id") $sFormattedValue = $oJson.StringOf("connections[i].addresses[j].formattedValue") $streetAddress = $oJson.StringOf("connections[i].addresses[j].streetAddress") $sCity = $oJson.StringOf("connections[i].addresses[j].city") $sRegion = $oJson.StringOf("connections[i].addresses[j].region") $sPostalCode = $oJson.StringOf("connections[i].addresses[j].postalCode") $sCountry = $oJson.StringOf("connections[i].addresses[j].country") $sCountryCode = $oJson.StringOf("connections[i].addresses[j].countryCode") $iJ = $iJ + 1 Wend $i = $i + 1 Wend |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.