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
(DataFlex) Google People API - Create ContactCreate a new contact. For more information, see https://developers.google.com/people/v1/contacts#create-a-new-contact
Use ChilkatAx-win32.pkg Procedure Test Variant vJson Token Handle hoJsonToken Boolean iSuccess Handle hoHttp Variant vJson Handle hoJson Variant vResp Handle hoResp Variant vSbResponseBody Handle hoSbResponseBody Handle hoJResp Integer iRespStatusCode String sV_type String sId String sUpdateTime Boolean iMetadataPrimary String sMetadataSourceType String sMetadataSourceId String sDisplayName String sFamilyName String sGivenName String sDisplayNameLastFirst String sUnstructuredName String sUrl Boolean iDefault String sContactGroupMembershipContactGroupId String sContactGroupMembershipContactGroupResourceName String sResourceName String sEtag String sMetadataObjectType Integer i Integer iCount_i String sTemp1 Boolean bTemp1 // 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 Get Create (RefClass(cComChilkatJsonObject)) To hoJsonToken If (Not(IsComObjectCreated(hoJsonToken))) Begin Send CreateComObject of hoJsonToken End Get ComLoadFile Of hoJsonToken "qa_data/tokens/googlePeople.json" To iSuccess If (iSuccess <> True) Begin Showln "Failed to load googleContacts.json" Procedure_Return End Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Get ComStringOf Of hoJsonToken "access_token" To sTemp1 Set ComAuthToken Of hoHttp To sTemp1 // Implements the following CURL command: // curl -H "Content-Type: application/json" -X POST // -d '{ // "names": [{ "givenName": "John", "familyName": "Doe" }] // }' // https://people.googleapis.com/v1/people:createContact // 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. // { // "names": [ // { // "givenName": "John", // "familyName": "Doe" // } // ] // } Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComUpdateString Of hoJson "names[0].givenName" "John" To iSuccess Get ComUpdateString Of hoJson "names[0].familyName" "Doe" To iSuccess Get pvComObject of hoJson to vJson Get ComPostJson3 Of hoHttp "https://people.googleapis.com/v1/people:createContact" "application/json" vJson To vResp If (IsComObject(vResp)) Begin Get Create (RefClass(cComChilkatHttpResponse)) To hoResp Set pvComObject Of hoResp To vResp End Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 = False) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody If (Not(IsComObjectCreated(hoSbResponseBody))) Begin Send CreateComObject of hoSbResponseBody End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess Get Create (RefClass(cComChilkatJsonObject)) To hoJResp If (Not(IsComObjectCreated(hoJResp))) Begin Send CreateComObject of hoJResp End Get pvComObject of hoSbResponseBody to vSbResponseBody Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess Set ComEmitCompact Of hoJResp To False Showln "Response Body:" Get ComEmit Of hoJResp To sTemp1 Showln sTemp1 Get ComStatusCode Of hoResp To iRespStatusCode Showln "Response Status Code = " iRespStatusCode If (iRespStatusCode >= 400) Begin Showln "Response Header:" Get ComHeader Of hoResp To sTemp1 Showln sTemp1 Showln "Failed." Send Destroy of hoResp Procedure_Return End Send Destroy of hoResp // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "resourceName": "people/c172365763025317520", // "etag": "%EigBAj0DBAUGBwgJPgoLPwwNDg8QQBESExQVFhc1GTQ3HyEiIyQlJicuGgQBAgUHIgxleVowR3U1SFZhcz0=", // "metadata": { // "sources": [ // { // "type": "CONTACT", // "id": "2645dbf8c902e90", // "etag": "#eyZ0Gu5HVas=", // "updateTime": "2020-08-03T22:46:03.410Z" // } // ], // "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/-XdUIqdMkCWA/AAAAAAAAAAI/AAAAAAAAAAA/V8BNOaftJmYG2hHugNzYued7G9QFdbZOACLcDEAEiGQoBShD___________8BGNuwiP7______wE/s100/photo.jpg", // "default": true // } // ], // "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 Get ComStringOf Of hoJResp "resourceName" To sResourceName Get ComStringOf Of hoJResp "etag" To sEtag Get ComStringOf Of hoJResp "metadata.objectType" To sMetadataObjectType Move 0 To i Get ComSizeOfArray Of hoJResp "metadata.sources" To iCount_i While (i < iCount_i) Set ComI Of hoJResp To i Get ComStringOf Of hoJResp "metadata.sources[i].type" To sV_type Get ComStringOf Of hoJResp "metadata.sources[i].id" To sId Get ComStringOf Of hoJResp "metadata.sources[i].etag" To sEtag Get ComStringOf Of hoJResp "metadata.sources[i].updateTime" To sUpdateTime Move (i + 1) To i Loop Move 0 To i Get ComSizeOfArray Of hoJResp "names" To iCount_i While (i < iCount_i) Set ComI Of hoJResp To i Get ComBoolOf Of hoJResp "names[i].metadata.primary" To iMetadataPrimary Get ComStringOf Of hoJResp "names[i].metadata.source.type" To sMetadataSourceType Get ComStringOf Of hoJResp "names[i].metadata.source.id" To sMetadataSourceId Get ComStringOf Of hoJResp "names[i].displayName" To sDisplayName Get ComStringOf Of hoJResp "names[i].familyName" To sFamilyName Get ComStringOf Of hoJResp "names[i].givenName" To sGivenName Get ComStringOf Of hoJResp "names[i].displayNameLastFirst" To sDisplayNameLastFirst Get ComStringOf Of hoJResp "names[i].unstructuredName" To sUnstructuredName Move (i + 1) To i Loop Move 0 To i Get ComSizeOfArray Of hoJResp "photos" To iCount_i While (i < iCount_i) Set ComI Of hoJResp To i Get ComBoolOf Of hoJResp "photos[i].metadata.primary" To iMetadataPrimary Get ComStringOf Of hoJResp "photos[i].metadata.source.type" To sMetadataSourceType Get ComStringOf Of hoJResp "photos[i].metadata.source.id" To sMetadataSourceId Get ComStringOf Of hoJResp "photos[i].url" To sUrl Get ComBoolOf Of hoJResp "photos[i].default" To iDefault Move (i + 1) To i Loop Move 0 To i Get ComSizeOfArray Of hoJResp "memberships" To iCount_i While (i < iCount_i) Set ComI Of hoJResp To i Get ComStringOf Of hoJResp "memberships[i].metadata.source.type" To sMetadataSourceType Get ComStringOf Of hoJResp "memberships[i].metadata.source.id" To sMetadataSourceId Get ComStringOf Of hoJResp "memberships[i].contactGroupMembership.contactGroupId" To sContactGroupMembershipContactGroupId Get ComStringOf Of hoJResp "memberships[i].contactGroupMembership.contactGroupResourceName" To sContactGroupMembershipContactGroupResourceName Move (i + 1) To i Loop End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.