Sample code for 30+ languages & platforms
Perl

MercadoLibre - Consultar mis datos personales

See more MercadoLibre Examples

Consultar mis datos personales

Chilkat Perl Downloads

Perl
use chilkat();

$success = 0;

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

$http = chilkat::CkHttp->new();

# First get our previously obtained OAuth2 access token.
$jsonToken = chilkat::CkJsonObject->new();
$success = $jsonToken->LoadFile("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

$http->SetUrlVar("access_token",$jsonToken->stringOf("access_token"));

$sbResponseBody = chilkat::CkStringBuilder->new();
$success = $http->QuickGetSb("https://api.mercadolibre.com/users/me?access_token={$access_token}",$sbResponseBody);
if ($success == 0) {
    print $http->lastErrorText() . "\r\n";
    exit;
}

$jResp = chilkat::CkJsonObject->new();
$jResp->LoadSb($sbResponseBody);
$jResp->put_EmitCompact(0);

print "Response Body:" . "\r\n";
print $jResp->emit() . "\r\n";

$respStatusCode = $http->get_LastStatus();
print "Response Status Code = " . $respStatusCode . "\r\n";
if ($respStatusCode >= 400) {
    print "Response Header:" . "\r\n";
    print $http->lastHeader() . "\r\n";
    print "Failed." . "\r\n";
    exit;
}

# 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 = $jResp->IntOf("id");
$nickname = $jResp->stringOf("nickname");
$registration_date = $jResp->stringOf("registration_date");
$country_id = $jResp->stringOf("country_id");
$addressState = $jResp->stringOf("address.state");
$addressCity = $jResp->stringOf("address.city");
$user_type = $jResp->stringOf("user_type");
$logo = $jResp->stringOf("logo");
$points = $jResp->IntOf("points");
$site_id = $jResp->stringOf("site_id");
$permalink = $jResp->stringOf("permalink");
$seller_reputationLevel_id = $jResp->stringOf("seller_reputation.level_id");
$seller_reputationPower_seller_status = $jResp->stringOf("seller_reputation.power_seller_status");
$seller_reputationTransactionsPeriod = $jResp->stringOf("seller_reputation.transactions.period");
$seller_reputationTransactionsTotal = $jResp->IntOf("seller_reputation.transactions.total");
$seller_reputationTransactionsCompleted = $jResp->IntOf("seller_reputation.transactions.completed");
$seller_reputationTransactionsCanceled = $jResp->IntOf("seller_reputation.transactions.canceled");
$seller_reputationTransactionsRatingsPositive = $jResp->IntOf("seller_reputation.transactions.ratings.positive");
$seller_reputationTransactionsRatingsNegative = $jResp->IntOf("seller_reputation.transactions.ratings.negative");
$seller_reputationTransactionsRatingsNeutral = $jResp->IntOf("seller_reputation.transactions.ratings.neutral");
$statusSite_status = $jResp->stringOf("status.site_status");
$i = 0;
$count_i = $jResp->SizeOfArray("tags");
while ($i < $count_i) {
    $jResp->put_I($i);
    $strVal = $jResp->stringOf("tags[i]");
    $i = $i + 1;
}

$i = 0;
$count_i = $jResp->SizeOfArray("buyer_reputation.tags");
while ($i < $count_i) {
    $jResp->put_I($i);
    $i = $i + 1;
}