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
(Unicode 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_CkHttpW.h> #include <C_CkHttpResponseW.h> #include <C_CkStringBuilderW.h> #include <C_CkJsonObjectW.h> #include <C_CkRestW.h> void ChilkatSample(void) { HCkHttpW http; HCkHttpResponseW resp; HCkStringBuilderW sbJson; HCkJsonObjectW json; HCkRestW 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 = CkHttpW_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. CkHttpW_putLogin(http,L"SHOPIFY_PRIVATE_API_KEY"); CkHttpW_putPassword(http,L"SHOPIFY_PRIVATE_API_SECRET_KEY"); CkHttpW_putBasicAuth(http,TRUE); // Make sure to replace "chilkat" with your store name. resp = CkHttpW_QuickGetObj(http,L"https://chilkat.myshopify.com/admin/products.json"); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); return; } // Examine the response code. if (CkHttpResponseW_getStatusCode(resp) != 200) { wprintf(L"Received error response code: %d\n",CkHttpResponseW_getStatusCode(resp)); wprintf(L"Response body:\n"); wprintf(L"%s\n",CkHttpResponseW_bodyStr(resp)); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); return; } // Success. wprintf(L"Success.\n"); // Examine the JSON response sbJson = CkStringBuilderW_Create(); CkHttpResponseW_GetBodySb(resp,sbJson); CkHttpResponseW_Dispose(resp); json = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(json,sbJson); CkJsonObjectW_putEmitCompact(json,FALSE); wprintf(L"%s\n",CkJsonObjectW_emit(json)); // ------------------------------------------------- // Now let's do the same using the Chilkat Rest API. rest = CkRestW_Create(); // Provide the private app credentials: CkRestW_SetAuthBasic(rest,L"SHOPIFY_PRIVATE_API_KEY",L"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 = CkRestW_Connect(rest,L"chilkat.myshopify.com",port,bTls,bAutoReconnect); if (success != TRUE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbJson); CkJsonObjectW_Dispose(json); CkRestW_Dispose(rest); return; } CkStringBuilderW_Clear(sbJson); success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/admin/products.json",sbJson); if (CkRestW_getLastMethodSuccess(rest) != TRUE) { wprintf(L"%s\n",CkRestW_lastErrorText(rest)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbJson); CkJsonObjectW_Dispose(json); CkRestW_Dispose(rest); return; } if (CkRestW_getResponseStatusCode(rest) != 200) { wprintf(L"Received error response code: %d\n",CkRestW_getResponseStatusCode(rest)); wprintf(L"Response body:\n"); wprintf(L"%s\n",CkStringBuilderW_getAsString(sbJson)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbJson); CkJsonObjectW_Dispose(json); CkRestW_Dispose(rest); return; } // Success... CkJsonObjectW_LoadSb(json,sbJson); wprintf(L"%s\n",CkJsonObjectW_emit(json)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbJson); CkJsonObjectW_Dispose(json); CkRestW_Dispose(rest); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.