Sample code for 30+ languages & platforms
Pascal (Lazarus/Delphi)

BrickLink OAuth1 using Chilkat HTTP

See more BrickLink Examples

Demonstrates sending an api.bricklink.com request with OAuth1 authentication using Chilkat HTTP.

Chilkat Pascal (Lazarus/Delphi) Downloads

Pascal (Lazarus/Delphi)
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.Http,
  Chilkat.HttpResponse,
  Chilkat.JsonObject;

// ---------------------------------------------------------------------------

procedure RunDemo;
var
  success: Boolean;
  http: THttp;
  resp: THttpResponse;
  json: TJsonObject;

begin
  success := False;

  //  This example assumes the Chilkat API to have been previously unlocked.
  //  See Global Unlock Sample for sample code.

  http := THttp.Create;

  http.OAuth1 := True;
  http.OAuthConsumerKey := 'Your Consumer Key';
  http.OAuthConsumerSecret := 'Your Consumer Secret';
  http.OAuthToken := 'Your OAuth1 Token';
  http.OAuthTokenSecret := 'Your Token Secret';
  http.OAuthSigMethod := 'HMAC-SHA1';

  resp := THttpResponse.Create;
  success := http.HttpNoBody('GET','https://api.bricklink.com/api/store/v1/orders?direction=in',resp);
  if (success = False) then
    begin
      WriteLn(http.LastErrorText);
      Exit;
    end;

  WriteLn('Response status code = ' + resp.StatusCode);

  json := TJsonObject.Create;
  resp.GetBodyJson(json);

  json.EmitCompact := False;
  WriteLn(json.Emit());


  http.Free;
  resp.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.