Lua
Lua
MercadoLibre - Consultar mis datos personales
See more MercadoLibre Examples
Consultar mis datos personalesChilkat Lua Downloads
local chilkat = require("chilkat")
-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.
local http = chilkat.Http.new()
-- First get our previously obtained OAuth2 access token.
local jsonToken = chilkat.JsonObject.new()
local success = jsonToken:load_file("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:set_url_var("access_token", jsonToken:string_of("access_token"))
local sbResponseBody = chilkat.StringBuilder.new()
success = http:quick_get_sb("https://api.mercadolibre.com/users/me?access_token={$access_token}", sbResponseBody)
if not success then
print(http.last_error_text)
return
end
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false
print("Response Body:")
print(jResp:emit())
local respStatusCode = http.last_status
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
print("Response Header:")
print(http.last_header)
print("Failed.")
return
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
local strVal = ""
local id = jResp:int_of("id")
local nickname = jResp:string_of("nickname")
local registration_date = jResp:string_of("registration_date")
local country_id = jResp:string_of("country_id")
local addressState = jResp:string_of("address.state")
local addressCity = jResp:string_of("address.city")
local user_type = jResp:string_of("user_type")
local logo = jResp:string_of("logo")
local points = jResp:int_of("points")
local site_id = jResp:string_of("site_id")
local permalink = jResp:string_of("permalink")
local seller_reputationLevel_id = jResp:string_of("seller_reputation.level_id")
local seller_reputationPower_seller_status = jResp:string_of("seller_reputation.power_seller_status")
local seller_reputationTransactionsPeriod = jResp:string_of("seller_reputation.transactions.period")
local seller_reputationTransactionsTotal = jResp:int_of("seller_reputation.transactions.total")
local seller_reputationTransactionsCompleted = jResp:int_of("seller_reputation.transactions.completed")
local seller_reputationTransactionsCanceled = jResp:int_of("seller_reputation.transactions.canceled")
local seller_reputationTransactionsRatingsPositive = jResp:int_of("seller_reputation.transactions.ratings.positive")
local seller_reputationTransactionsRatingsNegative = jResp:int_of("seller_reputation.transactions.ratings.negative")
local seller_reputationTransactionsRatingsNeutral = jResp:int_of("seller_reputation.transactions.ratings.neutral")
local statusSite_status = jResp:string_of("status.site_status")
local i = 0
local count_i = jResp:size_of_array("tags")
while i < count_i do
jResp.i = i
strVal = jResp:string_of("tags[i]")
i = i + 1
end
i = 0
count_i = jResp:size_of_array("buyer_reputation.tags")
while i < count_i do
jResp.i = i
i = i + 1
end