Perl
Perl
MercadoLibre - Consultar mis datos personales
See more MercadoLibre Examples
Consultar mis datos personalesChilkat Perl Downloads
use strict;
use warnings;
use Chilkat2;
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
my $http = Chilkat2::Http->new;
# First get our previously obtained OAuth2 access token.
my $jsonToken = Chilkat2::JsonObject->new;
my $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'));
my $sbResponseBody = Chilkat2::StringBuilder->new;
$success = $http->QuickGetSb('https://api.mercadolibre.com/users/me?access_token={$access_token}', $sbResponseBody);
if (!$success) {
print $http->LastErrorText, "\n";
exit;
}
my $jResp = Chilkat2::JsonObject->new;
$jResp->LoadSb($sbResponseBody);
$jResp->EmitCompact(0);
print "Response Body:\n";
print $jResp->Emit(), "\n";
my $respStatusCode = $http->LastStatus;
print 'Response Status Code = ', $respStatusCode, "\n";
if ($respStatusCode >= 400) {
print "Response Header:\n";
print $http->LastHeader, "\n";
print "Failed.\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
my $strVal = '';
my $id = $jResp->IntOf('id');
my $nickname = $jResp->StringOf('nickname');
my $registration_date = $jResp->StringOf('registration_date');
my $country_id = $jResp->StringOf('country_id');
my $addressState = $jResp->StringOf('address.state');
my $addressCity = $jResp->StringOf('address.city');
my $user_type = $jResp->StringOf('user_type');
my $logo = $jResp->StringOf('logo');
my $points = $jResp->IntOf('points');
my $site_id = $jResp->StringOf('site_id');
my $permalink = $jResp->StringOf('permalink');
my $seller_reputationLevel_id = $jResp->StringOf('seller_reputation.level_id');
my $seller_reputationPower_seller_status = $jResp->StringOf('seller_reputation.power_seller_status');
my $seller_reputationTransactionsPeriod = $jResp->StringOf('seller_reputation.transactions.period');
my $seller_reputationTransactionsTotal = $jResp->IntOf('seller_reputation.transactions.total');
my $seller_reputationTransactionsCompleted = $jResp->IntOf('seller_reputation.transactions.completed');
my $seller_reputationTransactionsCanceled = $jResp->IntOf('seller_reputation.transactions.canceled');
my $seller_reputationTransactionsRatingsPositive = $jResp->IntOf('seller_reputation.transactions.ratings.positive');
my $seller_reputationTransactionsRatingsNegative = $jResp->IntOf('seller_reputation.transactions.ratings.negative');
my $seller_reputationTransactionsRatingsNeutral = $jResp->IntOf('seller_reputation.transactions.ratings.neutral');
my $statusSite_status = $jResp->StringOf('status.site_status');
my $i = 0;
my $count_i = $jResp->SizeOfArray('tags');
while ($i < $count_i) {
$jResp->I($i);
$strVal = $jResp->StringOf('tags[i]');
$i = $i + 1;
}
$i = 0;
$count_i = $jResp->SizeOfArray('buyer_reputation.tags');
while ($i < $count_i) {
$jResp->I($i);
$i = $i + 1;
}