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
(Delphi DLL) 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.
uses Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, Rest, HttpResponse, JsonObject; ... procedure TForm1.Button1Click(Sender: TObject); var http: HCkHttp; resp: HCkHttpResponse; sbJson: HCkStringBuilder; json: HCkJsonObject; rest: HCkRest; bTls: Boolean; port: Integer; bAutoReconnect: Boolean; success: Boolean; begin // 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) then begin Memo1.Lines.Add(CkHttp__lastErrorText(http)); Exit; end; // Examine the response code. if (CkHttpResponse_getStatusCode(resp) <> 200) then begin Memo1.Lines.Add('Received error response code: ' + IntToStr(CkHttpResponse_getStatusCode(resp))); Memo1.Lines.Add('Response body:'); Memo1.Lines.Add(CkHttpResponse__bodyStr(resp)); CkHttpResponse_Dispose(resp); Exit; end; // Success. Memo1.Lines.Add('Success.'); // 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); Memo1.Lines.Add(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) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; CkStringBuilder_Clear(sbJson); success := CkRest_FullRequestNoBodySb(rest,'GET','/admin/products.json',sbJson); if (CkRest_getLastMethodSuccess(rest) <> True) then begin Memo1.Lines.Add(CkRest__lastErrorText(rest)); Exit; end; if (CkRest_getResponseStatusCode(rest) <> 200) then begin Memo1.Lines.Add('Received error response code: ' + IntToStr(CkRest_getResponseStatusCode(rest))); Memo1.Lines.Add('Response body:'); Memo1.Lines.Add(CkStringBuilder__getAsString(sbJson)); Exit; end; // Success... CkJsonObject_LoadSb(json,sbJson); Memo1.Lines.Add(CkJsonObject__emit(json)); CkHttp_Dispose(http); CkStringBuilder_Dispose(sbJson); CkJsonObject_Dispose(json); CkRest_Dispose(rest); end; |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.