Sample code for 30+ languages & platforms
Tcl

MercadoLibre - Consultar mis datos personales

See more MercadoLibre Examples

Consultar mis datos personales

Chilkat Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set http [new_CkHttp]

# First get our previously obtained OAuth2 access token.
set jsonToken [new_CkJsonObject]

set 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"]

set sbResponseBody [new_CkStringBuilder]

set success [CkHttp_QuickGetSb $http "https://api.mercadolibre.com/users/me?access_token={$access_token}" $sbResponseBody]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    delete_CkStringBuilder $sbResponseBody
    exit
}

set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttp_get_LastStatus $http]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttp_lastHeader $http]
    puts "Failed."
    delete_CkHttp $http
    delete_CkJsonObject $jsonToken
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    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

set id [CkJsonObject_IntOf $jResp "id"]
set nickname [CkJsonObject_stringOf $jResp "nickname"]
set registration_date [CkJsonObject_stringOf $jResp "registration_date"]
set country_id [CkJsonObject_stringOf $jResp "country_id"]
set addressState [CkJsonObject_stringOf $jResp "address.state"]
set addressCity [CkJsonObject_stringOf $jResp "address.city"]
set user_type [CkJsonObject_stringOf $jResp "user_type"]
set logo [CkJsonObject_stringOf $jResp "logo"]
set points [CkJsonObject_IntOf $jResp "points"]
set site_id [CkJsonObject_stringOf $jResp "site_id"]
set permalink [CkJsonObject_stringOf $jResp "permalink"]
set seller_reputationLevel_id [CkJsonObject_stringOf $jResp "seller_reputation.level_id"]
set seller_reputationPower_seller_status [CkJsonObject_stringOf $jResp "seller_reputation.power_seller_status"]
set seller_reputationTransactionsPeriod [CkJsonObject_stringOf $jResp "seller_reputation.transactions.period"]
set seller_reputationTransactionsTotal [CkJsonObject_IntOf $jResp "seller_reputation.transactions.total"]
set seller_reputationTransactionsCompleted [CkJsonObject_IntOf $jResp "seller_reputation.transactions.completed"]
set seller_reputationTransactionsCanceled [CkJsonObject_IntOf $jResp "seller_reputation.transactions.canceled"]
set seller_reputationTransactionsRatingsPositive [CkJsonObject_IntOf $jResp "seller_reputation.transactions.ratings.positive"]
set seller_reputationTransactionsRatingsNegative [CkJsonObject_IntOf $jResp "seller_reputation.transactions.ratings.negative"]
set seller_reputationTransactionsRatingsNeutral [CkJsonObject_IntOf $jResp "seller_reputation.transactions.ratings.neutral"]
set statusSite_status [CkJsonObject_stringOf $jResp "status.site_status"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "tags"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set strVal [CkJsonObject_stringOf $jResp "tags[i]"]
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "buyer_reputation.tags"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}

delete_CkHttp $http
delete_CkJsonObject $jsonToken
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp