Sample code for 30+ languages & platforms
Java

MercadoLibre - Consultar mis datos personales

See more MercadoLibre Examples

Consultar mis datos personales

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.Http;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example assumes the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Http http = new Http();

        // First get our previously obtained OAuth2 access token.
        JsonObject jsonToken = new JsonObject();
        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"));

        StringBuilder sbResponseBody = new StringBuilder();
        try {
            http.quickGetSb("https://api.mercadolibre.com/users/me?access_token={$access_token}", sbResponseBody);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        JsonObject jResp = new JsonObject();
        jResp.loadSb(sbResponseBody);
        jResp.setEmitCompact(false);

        System.out.println("Response Body:");
        System.out.println(jResp.emit());

        int respStatusCode = http.getLastStatus();
        System.out.println("Response Status Code = " + respStatusCode);
        if (respStatusCode >= 400) {
            System.out.println("Response Header:");
            System.out.println(http.getLastHeader());
            System.out.println("Failed.");
            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

        String strVal = "";

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

        i = 0;
        count_i = jResp.sizeOfArray("buyer_reputation.tags");
        while (i < count_i) {
            jResp.setI(i);
            i = i + 1;
        }
    }
}