Pascal (Lazarus/Delphi)
Pascal (Lazarus/Delphi)
MercadoLibre - GET Request with Authorization Bearer Access Token
See more MercadoLibre Examples
Demonstrates how to send an HTTPS GET request to MercadoLibre with an "Authorization: Bearer $ACCESS_TOKEN" header.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;
jsonToken: TJsonObject;
responseStr: string;
begin
success := False;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := THttp.Create;
// First get our previously obtained OAuth2 access token.
jsonToken := TJsonObject.Create;
success := jsonToken.LoadFile('qa_data/tokens/mercadolibre.json');
if (success = False) then
begin
WriteLn('Failed to load JSON access token.');
Exit;
end;
// This adds the "Authorization: Bearer $ACCESS_TOKEN" header field.
http.AuthToken := jsonToken.StringOf('access_token');
// Use your seller ID.
http.SetUrlVar('SELLER_ID','577815702');
responseStr := http.QuickGetStr('https://api.mercadolibre.com/questions/search?seller_id={$SELLER_ID}&api_version=4');
if (http.LastMethodSuccess = False) then
begin
WriteLn(http.LastErrorText);
Exit;
end;
WriteLn(responseStr);
http.Free;
jsonToken.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.