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
(PowerBuilder) Google People API - Update an Existing ContactTo update an existing contact, you must include the person.metadata.sources.etag field in the person for the contact to be updated to make sure the contact has not changed since your last read. For more information, see https://developers.google.com/people/v1/contacts#update-an-existing-contact
integer li_rc oleobject loo_JsonToken integer li_Success oleobject loo_Http oleobject loo_Json oleobject loo_SbRequestBody oleobject loo_Resp oleobject loo_SbResponseBody oleobject loo_JResp integer li_RespStatusCode string ls_V_type string ls_Id string ls_UpdateTime 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_Url integer li_Default string ls_Value string ls_ContactGroupMembershipContactGroupId string ls_ContactGroupMembershipContactGroupResourceName string ls_ResourceName string ls_Etag string ls_MetadataObjectType integer i integer li_Count_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 loo_JsonToken = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 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 // Use "Chilkat_9_5_0.Http" for versions of Chilkat < 10.0.0 li_rc = loo_Http.ConnectToNewObject("Chilkat.Http") loo_Http.AuthToken = loo_JsonToken.StringOf("access_token") // Implements the following CURL command: // curl -X PATCH https://people.googleapis.com/v1/resource_name:updateContact?updatePersonFields=emailAddresses \ // -H "Content-Type: application/json" \ // -d '{ // "resourceName": "resource_name", // "etag": "#eyZ0Gu5HVas=", // "emailAddresses": [{ "value": "john.doe@gmail.com" }], // }' // Use the following online tool to generate HTTP code from a CURL command // Convert a cURL Command to HTTP Source Code // Use this online tool to generate code from sample JSON: // Generate Code to Create JSON // The following JSON is sent in the request body. // { // "resourceName": "resource_name", // "etag": "#eyZ0Gu5HVas=", // "emailAddresses": [ // { // "value": "john.doe@gmail.com" // } // ] // } loo_Json = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject") loo_Json.UpdateString("resourceName","people/c172365763025317520") loo_Json.UpdateString("etag","%EigBAj0DBAUGBwgJPgoLPwwNDg8QQBESExQVFhc1GTQ3HyEiIyQlJicuGgQBAgUHIgxleVowR3U1SFZhcz0=") loo_Json.UpdateString("emailAddresses[0].value","john.doe@gmail.com") loo_SbRequestBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbRequestBody.ConnectToNewObject("Chilkat.StringBuilder") loo_Json.EmitSb(loo_SbRequestBody) // Notice that the resource name is part of the URL... loo_Resp = loo_Http.PTextSb("PATCH","https://people.googleapis.com/v1/people/c172365763025317520:updateContact?updatePersonFields=emailAddresses",loo_SbRequestBody,"utf-8","application/json",0,0) if loo_Http.LastMethodSuccess = 0 then Write-Debug loo_Http.LastErrorText destroy loo_JsonToken destroy loo_Http destroy loo_Json destroy loo_SbRequestBody return end if loo_SbResponseBody = create oleobject // Use "Chilkat_9_5_0.StringBuilder" for versions of Chilkat < 10.0.0 li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder") loo_Resp.GetBodySb(loo_SbResponseBody) loo_JResp = create oleobject // Use "Chilkat_9_5_0.JsonObject" for versions of Chilkat < 10.0.0 li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject") loo_JResp.LoadSb(loo_SbResponseBody) loo_JResp.EmitCompact = 0 Write-Debug "Response Body:" Write-Debug loo_JResp.Emit() li_RespStatusCode = loo_Resp.StatusCode Write-Debug "Response Status Code = " + string(li_RespStatusCode) if li_RespStatusCode >= 400 then Write-Debug "Response Header:" Write-Debug loo_Resp.Header Write-Debug "Failed." destroy loo_Resp destroy loo_JsonToken destroy loo_Http destroy loo_Json destroy loo_SbRequestBody destroy loo_SbResponseBody destroy loo_JResp return end if destroy loo_Resp // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "resourceName": "people/c172365763025317520", // "etag": "%EigBAj0DBAUGBwgJPgoLPwwNDg8QQBESExQVFhc1GTQ3HyEiIyQlJicuGgQBAgUHIgxtQnhyR2MzMGU4Yz0=", // "metadata": { // "sources": [ // { // "type": "CONTACT", // "id": "2645dbf8c902e90", // "etag": "#mBxrGc30e8c=", // "updateTime": "2020-08-03T23:01:23.539Z" // } // ], // "objectType": "PERSON" // }, // "names": [ // { // "metadata": { // "primary": true, // "source": { // "type": "CONTACT", // "id": "2645dbf8c902e90" // } // }, // "displayName": "John Doe", // "familyName": "Doe", // "givenName": "John", // "displayNameLastFirst": "Doe, John", // "unstructuredName": "John Doe" // } // ], // "photos": [ // { // "metadata": { // "primary": true, // "source": { // "type": "CONTACT", // "id": "2645dbf8c902e90" // } // }, // "url": "https://lh3.googleusercontent.com/-XdUIqeMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/V8BNOaftJmYG2hHugNzYued7G9QFdeZOACLcDEAEiGQoBShD___________8BGNvwiP7______wE/s100/photo.jpg", // "default": true // } // ], // "emailAddresses": [ // { // "metadata": { // "primary": true, // "source": { // "type": "CONTACT", // "id": "2645def8c902e90" // } // }, // "value": "john.doe@gmail.com" // } // ], // "memberships": [ // { // "metadata": { // "source": { // "type": "CONTACT", // "id": "2645dbf8c902e90" // } // }, // "contactGroupMembership": { // "contactGroupId": "myContacts", // "contactGroupResourceName": "contactGroups/myContacts" // } // } // ] // } // Sample code for parsing the JSON response... // Use the following online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON ls_ResourceName = loo_JResp.StringOf("resourceName") ls_Etag = loo_JResp.StringOf("etag") ls_MetadataObjectType = loo_JResp.StringOf("metadata.objectType") i = 0 li_Count_i = loo_JResp.SizeOfArray("metadata.sources") do while i < li_Count_i loo_JResp.I = i ls_V_type = loo_JResp.StringOf("metadata.sources[i].type") ls_Id = loo_JResp.StringOf("metadata.sources[i].id") ls_Etag = loo_JResp.StringOf("metadata.sources[i].etag") ls_UpdateTime = loo_JResp.StringOf("metadata.sources[i].updateTime") i = i + 1 loop i = 0 li_Count_i = loo_JResp.SizeOfArray("names") do while i < li_Count_i loo_JResp.I = i li_MetadataPrimary = loo_JResp.BoolOf("names[i].metadata.primary") ls_MetadataSourceType = loo_JResp.StringOf("names[i].metadata.source.type") ls_MetadataSourceId = loo_JResp.StringOf("names[i].metadata.source.id") ls_DisplayName = loo_JResp.StringOf("names[i].displayName") ls_FamilyName = loo_JResp.StringOf("names[i].familyName") ls_GivenName = loo_JResp.StringOf("names[i].givenName") ls_DisplayNameLastFirst = loo_JResp.StringOf("names[i].displayNameLastFirst") ls_UnstructuredName = loo_JResp.StringOf("names[i].unstructuredName") i = i + 1 loop i = 0 li_Count_i = loo_JResp.SizeOfArray("photos") do while i < li_Count_i loo_JResp.I = i li_MetadataPrimary = loo_JResp.BoolOf("photos[i].metadata.primary") ls_MetadataSourceType = loo_JResp.StringOf("photos[i].metadata.source.type") ls_MetadataSourceId = loo_JResp.StringOf("photos[i].metadata.source.id") ls_Url = loo_JResp.StringOf("photos[i].url") li_Default = loo_JResp.BoolOf("photos[i].default") i = i + 1 loop i = 0 li_Count_i = loo_JResp.SizeOfArray("emailAddresses") do while i < li_Count_i loo_JResp.I = i li_MetadataPrimary = loo_JResp.BoolOf("emailAddresses[i].metadata.primary") ls_MetadataSourceType = loo_JResp.StringOf("emailAddresses[i].metadata.source.type") ls_MetadataSourceId = loo_JResp.StringOf("emailAddresses[i].metadata.source.id") ls_Value = loo_JResp.StringOf("emailAddresses[i].value") i = i + 1 loop i = 0 li_Count_i = loo_JResp.SizeOfArray("memberships") do while i < li_Count_i loo_JResp.I = i ls_MetadataSourceType = loo_JResp.StringOf("memberships[i].metadata.source.type") ls_MetadataSourceId = loo_JResp.StringOf("memberships[i].metadata.source.id") ls_ContactGroupMembershipContactGroupId = loo_JResp.StringOf("memberships[i].contactGroupMembership.contactGroupId") ls_ContactGroupMembershipContactGroupResourceName = loo_JResp.StringOf("memberships[i].contactGroupMembership.contactGroupResourceName") i = i + 1 loop destroy loo_JsonToken destroy loo_Http destroy loo_Json destroy loo_SbRequestBody destroy loo_SbResponseBody destroy loo_JResp |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.