Sample code for 30+ languages & platforms
Unicode C++

MercadoLibre - Consultar mis datos personales

See more MercadoLibre Examples

Consultar mis datos personales

Chilkat Unicode C++ Downloads

Unicode C++
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkStringBuilderW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;

    //  First get our previously obtained OAuth2 access token.
    CkJsonObjectW jsonToken;
    success = jsonToken.LoadFile(L"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(L"access_token",jsonToken.stringOf(L"access_token"));

    CkStringBuilderW sbResponseBody;
    success = http.QuickGetSb(L"https://api.mercadolibre.com/users/me?access_token={$access_token}",sbResponseBody);
    if (success == false) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkJsonObjectW jResp;
    jResp.LoadSb(sbResponseBody);
    jResp.put_EmitCompact(false);

    wprintf(L"Response Body:\n");
    wprintf(L"%s\n",jResp.emit());

    int respStatusCode = http.get_LastStatus();
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",http.lastHeader());
        wprintf(L"Failed.\n");
        return;
    }

    //  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

    //  Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    //  See this example explaining how this memory should be used: const char * functions.

    const wchar_t *strVal = 0;

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

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