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 <C_CkHttpW.h>
#include <C_CkJsonObjectW.h>
#include <C_CkStringBuilderW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkJsonObjectW jsonToken;
    HCkStringBuilderW sbResponseBody;
    HCkJsonObjectW jResp;
    int respStatusCode;
    const wchar_t *strVal;
    int id;
    const wchar_t *nickname;
    const wchar_t *registration_date;
    const wchar_t *country_id;
    const wchar_t *addressState;
    const wchar_t *addressCity;
    const wchar_t *user_type;
    const wchar_t *logo;
    int points;
    const wchar_t *site_id;
    const wchar_t *permalink;
    const wchar_t *seller_reputationLevel_id;
    const wchar_t *seller_reputationPower_seller_status;
    const wchar_t *seller_reputationTransactionsPeriod;
    int seller_reputationTransactionsTotal;
    int seller_reputationTransactionsCompleted;
    int seller_reputationTransactionsCanceled;
    int seller_reputationTransactionsRatingsPositive;
    int seller_reputationTransactionsRatingsNegative;
    int seller_reputationTransactionsRatingsNeutral;
    const wchar_t *statusSite_status;
    int i;
    int count_i;

    success = FALSE;

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

    http = CkHttpW_Create();

    // First get our previously obtained OAuth2 access token.
    jsonToken = CkJsonObjectW_Create();
    success = CkJsonObjectW_LoadFile(jsonToken,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

    CkHttpW_SetUrlVar(http,L"access_token",CkJsonObjectW_stringOf(jsonToken,L"access_token"));

    sbResponseBody = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,L"https://api.mercadolibre.com/users/me?access_token={$access_token}",sbResponseBody);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbResponseBody);
        return;
    }

    jResp = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(jResp,sbResponseBody);
    CkJsonObjectW_putEmitCompact(jResp,FALSE);

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

    respStatusCode = CkHttpW_getLastStatus(http);
    wprintf(L"Response Status Code = %d\n",respStatusCode);
    if (respStatusCode >= 400) {
        wprintf(L"Response Header:\n");
        wprintf(L"%s\n",CkHttpW_lastHeader(http));
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkJsonObjectW_Dispose(jsonToken);
        CkStringBuilderW_Dispose(sbResponseBody);
        CkJsonObjectW_Dispose(jResp);
        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.

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

    i = 0;
    count_i = CkJsonObjectW_SizeOfArray(jResp,L"buyer_reputation.tags");
    while (i < count_i) {
        CkJsonObjectW_putI(jResp,i);
        i = i + 1;
    }



    CkHttpW_Dispose(http);
    CkJsonObjectW_Dispose(jsonToken);
    CkStringBuilderW_Dispose(sbResponseBody);
    CkJsonObjectW_Dispose(jResp);

    }