Sample code for 30+ languages & platforms
Delphi DLL

MercadoLibre - Consultar mis datos personales

See more MercadoLibre Examples

Consultar mis datos personales

Chilkat Delphi DLL Downloads

Delphi DLL
uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Http, StringBuilder, JsonObject;

...

procedure TForm1.Button1Click(Sender: TObject);
var
success: Boolean;
http: HCkHttp;
jsonToken: HCkJsonObject;
sbResponseBody: HCkStringBuilder;
jResp: HCkJsonObject;
respStatusCode: Integer;
strVal: PWideChar;
id: Integer;
nickname: PWideChar;
registration_date: PWideChar;
country_id: PWideChar;
addressState: PWideChar;
addressCity: PWideChar;
user_type: PWideChar;
logo: PWideChar;
points: Integer;
site_id: PWideChar;
permalink: PWideChar;
seller_reputationLevel_id: PWideChar;
seller_reputationPower_seller_status: PWideChar;
seller_reputationTransactionsPeriod: PWideChar;
seller_reputationTransactionsTotal: Integer;
seller_reputationTransactionsCompleted: Integer;
seller_reputationTransactionsCanceled: Integer;
seller_reputationTransactionsRatingsPositive: Integer;
seller_reputationTransactionsRatingsNegative: Integer;
seller_reputationTransactionsRatingsNeutral: Integer;
statusSite_status: PWideChar;
i: Integer;
count_i: Integer;

begin
success := False;

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

http := CkHttp_Create();

// First get our previously obtained OAuth2 access token.
jsonToken := CkJsonObject_Create();
success := CkJsonObject_LoadFile(jsonToken,'qa_data/tokens/mercadolibre.json');

// Implements the following CURL command:

// curl - X GET https://api.mercadolibre.com/users/me?access_token=$ACCESS_TOKEN

// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code

CkHttp_SetUrlVar(http,'access_token',CkJsonObject__stringOf(jsonToken,'access_token'));

sbResponseBody := CkStringBuilder_Create();
success := CkHttp_QuickGetSb(http,'https://api.mercadolibre.com/users/me?access_token={$access_token}',sbResponseBody);
if (success = False) then
  begin
    Memo1.Lines.Add(CkHttp__lastErrorText(http));
    Exit;
  end;

jResp := CkJsonObject_Create();
CkJsonObject_LoadSb(jResp,sbResponseBody);
CkJsonObject_putEmitCompact(jResp,False);

Memo1.Lines.Add('Response Body:');
Memo1.Lines.Add(CkJsonObject__emit(jResp));

respStatusCode := CkHttp_getLastStatus(http);
Memo1.Lines.Add('Response Status Code = ' + IntToStr(respStatusCode));
if (respStatusCode >= 400) then
  begin
    Memo1.Lines.Add('Response Header:');
    Memo1.Lines.Add(CkHttp__lastHeader(http));
    Memo1.Lines.Add('Failed.');
    Exit;
  end;

// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)

// {
//   "id": 202593498,
//   "nickname": "TETE2870021",
//   "registration_date": "2016-01-06T11: 31: 42.000-04: 00",
//   "country_id": "AR",
//   "address": {
//     "state": "AR-C",
//     "city": "Palermo"
//   },
//   "user_type": "normal",
//   "tags": [
//     "normal",
//     "test_user",
//     "user_info_verified"
//   ],
//   "logo": null,
//   "points": 100,
//   "site_id": "MLA",
//   "permalink": "http://perfil.mercadolibre.com.ar/TETE2870021",
//   "seller_reputation": {
//     "level_id": null,
//     "power_seller_status": null,
//     "transactions": {
//       "period": "historic",
//       "total": 0,
//       "completed": 0,
//       "canceled": 0,
//       "ratings": {
//         "positive": 0,
//         "negative": 0,
//         "neutral": 0
//       }
//     }
//   },
//   "buyer_reputation": {
//     "tags": [
//     ]
//   },
//   "status": {
//     "site_status": "active"
//   }
// }

// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON

id := CkJsonObject_IntOf(jResp,'id');
nickname := CkJsonObject__stringOf(jResp,'nickname');
registration_date := CkJsonObject__stringOf(jResp,'registration_date');
country_id := CkJsonObject__stringOf(jResp,'country_id');
addressState := CkJsonObject__stringOf(jResp,'address.state');
addressCity := CkJsonObject__stringOf(jResp,'address.city');
user_type := CkJsonObject__stringOf(jResp,'user_type');
logo := CkJsonObject__stringOf(jResp,'logo');
points := CkJsonObject_IntOf(jResp,'points');
site_id := CkJsonObject__stringOf(jResp,'site_id');
permalink := CkJsonObject__stringOf(jResp,'permalink');
seller_reputationLevel_id := CkJsonObject__stringOf(jResp,'seller_reputation.level_id');
seller_reputationPower_seller_status := CkJsonObject__stringOf(jResp,'seller_reputation.power_seller_status');
seller_reputationTransactionsPeriod := CkJsonObject__stringOf(jResp,'seller_reputation.transactions.period');
seller_reputationTransactionsTotal := CkJsonObject_IntOf(jResp,'seller_reputation.transactions.total');
seller_reputationTransactionsCompleted := CkJsonObject_IntOf(jResp,'seller_reputation.transactions.completed');
seller_reputationTransactionsCanceled := CkJsonObject_IntOf(jResp,'seller_reputation.transactions.canceled');
seller_reputationTransactionsRatingsPositive := CkJsonObject_IntOf(jResp,'seller_reputation.transactions.ratings.positive');
seller_reputationTransactionsRatingsNegative := CkJsonObject_IntOf(jResp,'seller_reputation.transactions.ratings.negative');
seller_reputationTransactionsRatingsNeutral := CkJsonObject_IntOf(jResp,'seller_reputation.transactions.ratings.neutral');
statusSite_status := CkJsonObject__stringOf(jResp,'status.site_status');
i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'tags');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    strVal := CkJsonObject__stringOf(jResp,'tags[i]');
    i := i + 1;
  end;

i := 0;
count_i := CkJsonObject_SizeOfArray(jResp,'buyer_reputation.tags');
while i < count_i do
  begin
    CkJsonObject_putI(jResp,i);
    i := i + 1;
  end;

CkHttp_Dispose(http);
CkJsonObject_Dispose(jsonToken);
CkStringBuilder_Dispose(sbResponseBody);
CkJsonObject_Dispose(jResp);

end;