Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
Magento Request with OAuth1.0a Authentication
See more Magento Examples
Demonstrates sending a Magento request with OAuth1.0a authentication. (Using the Magento 1.x REST API)Chilkat Pascal (Lazarus/Delphi) Downloads
program ChilkatDemo;
// Demonstrates using the Chilkat Pascal wrapper via the C bridge DLL.
// Builds as a console application under Lazarus (FPC) or Delphi.
{$IFDEF FPC}
{$MODE DELPHI}
{$ENDIF}
{$APPTYPE CONSOLE}
uses
{$IFDEF UNIX}
cthreads,
{$ENDIF}
SysUtils,
CkDllLoader,
Chilkat.JsonObject,
Chilkat.Http;
// ---------------------------------------------------------------------------
procedure RunDemo;
var
success: Boolean;
http: THttp;
url: string;
jsonStr: string;
json: TJsonObject;
begin
success := False;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := THttp.Create;
http.OAuth1 := True;
http.OAuthVerifier := '';
http.OAuthConsumerKey := 'MAGENTO_CONSUMER_KEY';
http.OAuthConsumerSecret := 'MAGENTO_CONSUMER_SECRET';
http.OAuthToken := 'MAGENTO__TOKEN';
http.OAuthTokenSecret := 'MAGENTO_TOKEN_SECRET';
http.Accept := 'application/json';
url := 'http://www.inart.com/api/rest/products/store/2?limit=20&page=1';
jsonStr := http.QuickGetStr(url);
if (http.LastMethodSuccess <> True) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
WriteLn('Response status code = ' + http.LastStatus);
json := TJsonObject.Create;
json.Load(jsonStr);
json.EmitCompact := False;
WriteLn(json.Emit());
// Use this online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
http.Free;
json.Free;
end;
// ---------------------------------------------------------------------------
begin
try
RunDemo;
except
on E: Exception do
WriteLn('Unhandled exception: ', E.ClassName, ': ', E.Message);
end;
WriteLn;
{$IFDEF MSWINDOWS}
WriteLn('Press Enter to exit...');
ReadLn;
{$ENDIF}
end.