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
(C) Shopify Private Authentication for Private AppsShopify private authentication is for interacting with your own store through private applications. It uses HTTP "Basic" authentication with your Shopify private application key and secret key. This example demonstrates how to send a private authenticated request using Chilkat Http, and then the same using Chilkat Rest.
#include <C_CkHttp.h> #include <C_CkHttpResponse.h> #include <C_CkStringBuilder.h> #include <C_CkJsonObject.h> #include <C_CkRest.h> void ChilkatSample(void) { HCkHttp http; HCkHttpResponse resp; HCkStringBuilder sbJson; HCkJsonObject json; HCkRest rest; BOOL bTls; int port; BOOL bAutoReconnect; BOOL success; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // First demonstrate sending a simple request using Shopify private authentication w/ the Chilkat Http API. http = CkHttp_Create(); // To use HTTP Basic Authentication with any HTTP request, we simply set the Login, Password, and BasicAuth properties. // Important: All HTTP requests using Basic authentication must be over SSL/TLS. CkHttp_putLogin(http,"SHOPIFY_PRIVATE_API_KEY"); CkHttp_putPassword(http,"SHOPIFY_PRIVATE_API_SECRET_KEY"); CkHttp_putBasicAuth(http,TRUE); // Make sure to replace "chilkat" with your store name. resp = CkHttp_QuickGetObj(http,"https://chilkat.myshopify.com/admin/products.json"); if (CkHttp_getLastMethodSuccess(http) != TRUE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); return; } // Examine the response code. if (CkHttpResponse_getStatusCode(resp) != 200) { printf("Received error response code: %d\n",CkHttpResponse_getStatusCode(resp)); printf("Response body:\n"); printf("%s\n",CkHttpResponse_bodyStr(resp)); CkHttpResponse_Dispose(resp); CkHttp_Dispose(http); return; } // Success. printf("Success.\n"); // Examine the JSON response sbJson = CkStringBuilder_Create(); CkHttpResponse_GetBodySb(resp,sbJson); CkHttpResponse_Dispose(resp); json = CkJsonObject_Create(); CkJsonObject_LoadSb(json,sbJson); CkJsonObject_putEmitCompact(json,FALSE); printf("%s\n",CkJsonObject_emit(json)); // ------------------------------------------------- // Now let's do the same using the Chilkat Rest API. rest = CkRest_Create(); // Provide the private app credentials: CkRest_SetAuthBasic(rest,"SHOPIFY_PRIVATE_API_KEY","SHOPIFY_PRIVATE_API_SECRET_KEY"); // Connect to the shopify server. bTls = TRUE; port = 443; bAutoReconnect = TRUE; // Make sure to replace "chilkat" with your store name. success = CkRest_Connect(rest,"chilkat.myshopify.com",port,bTls,bAutoReconnect); if (success != TRUE) { printf("%s\n",CkRest_lastErrorText(rest)); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbJson); CkJsonObject_Dispose(json); CkRest_Dispose(rest); return; } CkStringBuilder_Clear(sbJson); success = CkRest_FullRequestNoBodySb(rest,"GET","/admin/products.json",sbJson); if (CkRest_getLastMethodSuccess(rest) != TRUE) { printf("%s\n",CkRest_lastErrorText(rest)); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbJson); CkJsonObject_Dispose(json); CkRest_Dispose(rest); return; } if (CkRest_getResponseStatusCode(rest) != 200) { printf("Received error response code: %d\n",CkRest_getResponseStatusCode(rest)); printf("Response body:\n"); printf("%s\n",CkStringBuilder_getAsString(sbJson)); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbJson); CkJsonObject_Dispose(json); CkRest_Dispose(rest); return; } // Success... CkJsonObject_LoadSb(json,sbJson); printf("%s\n",CkJsonObject_emit(json)); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbJson); CkJsonObject_Dispose(json); CkRest_Dispose(rest); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.