Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(C) MercadoLibre - Consultar mis datos personalesConsultar mis datos personales For more information, see https://developers.mercadolibre.com.ar/es_ar/servicios-consulta-usuarios
#include <C_CkHttp.h> #include <C_CkJsonObject.h> #include <C_CkStringBuilder.h> void ChilkatSample(void) { HCkHttp http; HCkJsonObject jsonToken; BOOL success; HCkStringBuilder sbResponseBody; HCkJsonObject jResp; int respStatusCode; const char *strVal; int id; const char *nickname; const char *registration_date; const char *country_id; const char *addressState; const char *addressCity; const char *user_type; const char *logo; int points; const char *site_id; const char *permalink; const char *seller_reputationLevel_id; const char *seller_reputationPower_seller_status; const char *seller_reputationTransactionsPeriod; int seller_reputationTransactionsTotal; int seller_reputationTransactionsCompleted; int seller_reputationTransactionsCanceled; int seller_reputationTransactionsRatingsPositive; int seller_reputationTransactionsRatingsNegative; int seller_reputationTransactionsRatingsNeutral; const char *statusSite_status; int i; int count_i; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttp_Create(); // First get our previously obtained OAuth2 access token. jsonToken = CkJsonObject_Create(); 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")); sbResponseBody = CkStringBuilder_Create(); success = CkHttp_QuickGetSb(http,"https://api.mercadolibre.com/users/me?access_token={$access_token}",sbResponseBody); if (success == FALSE) { printf("%s\n",CkHttp_lastErrorText(http)); CkHttp_Dispose(http); CkJsonObject_Dispose(jsonToken); CkStringBuilder_Dispose(sbResponseBody); return; } jResp = CkJsonObject_Create(); CkJsonObject_LoadSb(jResp,sbResponseBody); CkJsonObject_putEmitCompact(jResp,FALSE); printf("Response Body:\n"); printf("%s\n",CkJsonObject_emit(jResp)); respStatusCode = CkHttp_getLastStatus(http); printf("Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { printf("Response Header:\n"); printf("%s\n",CkHttp_lastHeader(http)); printf("Failed.\n"); CkHttp_Dispose(http); CkJsonObject_Dispose(jsonToken); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_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 = CkJsonObject_IntOf(jResp,"id"); nickname = CkJsonObject_stringOf(jResp,"nickname"); registration_date = CkJsonObject_stringOf(jResp,"registration_date"); country_id = CkJsonObject_stringOf(jResp,"country_id"); addressState = CkJsonObject_stringOf(jResp,"address.state"); addressCity = CkJsonObject_stringOf(jResp,"address.city"); user_type = CkJsonObject_stringOf(jResp,"user_type"); logo = CkJsonObject_stringOf(jResp,"logo"); points = CkJsonObject_IntOf(jResp,"points"); site_id = CkJsonObject_stringOf(jResp,"site_id"); permalink = CkJsonObject_stringOf(jResp,"permalink"); seller_reputationLevel_id = CkJsonObject_stringOf(jResp,"seller_reputation.level_id"); seller_reputationPower_seller_status = CkJsonObject_stringOf(jResp,"seller_reputation.power_seller_status"); seller_reputationTransactionsPeriod = CkJsonObject_stringOf(jResp,"seller_reputation.transactions.period"); seller_reputationTransactionsTotal = CkJsonObject_IntOf(jResp,"seller_reputation.transactions.total"); seller_reputationTransactionsCompleted = CkJsonObject_IntOf(jResp,"seller_reputation.transactions.completed"); seller_reputationTransactionsCanceled = CkJsonObject_IntOf(jResp,"seller_reputation.transactions.canceled"); seller_reputationTransactionsRatingsPositive = CkJsonObject_IntOf(jResp,"seller_reputation.transactions.ratings.positive"); seller_reputationTransactionsRatingsNegative = CkJsonObject_IntOf(jResp,"seller_reputation.transactions.ratings.negative"); seller_reputationTransactionsRatingsNeutral = CkJsonObject_IntOf(jResp,"seller_reputation.transactions.ratings.neutral"); statusSite_status = CkJsonObject_stringOf(jResp,"status.site_status"); i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"tags"); while (i < count_i) { CkJsonObject_putI(jResp,i); strVal = CkJsonObject_stringOf(jResp,"tags[i]"); i = i + 1; } i = 0; count_i = CkJsonObject_SizeOfArray(jResp,"buyer_reputation.tags"); while (i < count_i) { CkJsonObject_putI(jResp,i); i = i + 1; } CkHttp_Dispose(http); CkJsonObject_Dispose(jsonToken); CkStringBuilder_Dispose(sbResponseBody); CkJsonObject_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.