Sample code for 30+ languages & platforms
Visual FoxPro

MercadoLibre - Consultar mis datos personales

See more MercadoLibre Examples

Consultar mis datos personales

Chilkat Visual FoxPro Downloads

Visual FoxPro
LOCAL lnSuccess
LOCAL loHttp
LOCAL loJsonToken
LOCAL loSbResponseBody
LOCAL loJResp
LOCAL lnRespStatusCode
LOCAL lcStrVal
LOCAL lnId
LOCAL lcNickname
LOCAL lcRegistration_date
LOCAL lcCountry_id
LOCAL lcAddressState
LOCAL lcAddressCity
LOCAL lcUser_type
LOCAL lcLogo
LOCAL lnPoints
LOCAL lcSite_id
LOCAL lcPermalink
LOCAL lcSeller_reputationLevel_id
LOCAL lcSeller_reputationPower_seller_status
LOCAL lcSeller_reputationTransactionsPeriod
LOCAL lnSeller_reputationTransactionsTotal
LOCAL lnSeller_reputationTransactionsCompleted
LOCAL lnSeller_reputationTransactionsCanceled
LOCAL lnSeller_reputationTransactionsRatingsPositive
LOCAL lnSeller_reputationTransactionsRatingsNegative
LOCAL lnSeller_reputationTransactionsRatingsNeutral
LOCAL lcStatusSite_status
LOCAL i
LOCAL lnCount_i

lnSuccess = 0

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

loHttp = CreateObject('Chilkat.Http')

* First get our previously obtained OAuth2 access token.
loJsonToken = CreateObject('Chilkat.JsonObject')
lnSuccess = loJsonToken.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

loHttp.SetUrlVar("access_token",loJsonToken.StringOf("access_token"))

loSbResponseBody = CreateObject('Chilkat.StringBuilder')
lnSuccess = loHttp.QuickGetSb("https://api.mercadolibre.com/users/me?access_token={$access_token}",loSbResponseBody)
IF (lnSuccess = 0) THEN
    ? loHttp.LastErrorText
    RELEASE loHttp
    RELEASE loJsonToken
    RELEASE loSbResponseBody
    CANCEL
ENDIF

loJResp = CreateObject('Chilkat.JsonObject')
loJResp.LoadSb(loSbResponseBody)
loJResp.EmitCompact = 0

? "Response Body:"
? loJResp.Emit()

lnRespStatusCode = loHttp.LastStatus
? "Response Status Code = " + STR(lnRespStatusCode)
IF (lnRespStatusCode >= 400) THEN
    ? "Response Header:"
    ? loHttp.LastHeader
    ? "Failed."
    RELEASE loHttp
    RELEASE loJsonToken
    RELEASE loSbResponseBody
    RELEASE loJResp
    CANCEL
ENDIF

* 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

lnId = loJResp.IntOf("id")
lcNickname = loJResp.StringOf("nickname")
lcRegistration_date = loJResp.StringOf("registration_date")
lcCountry_id = loJResp.StringOf("country_id")
lcAddressState = loJResp.StringOf("address.state")
lcAddressCity = loJResp.StringOf("address.city")
lcUser_type = loJResp.StringOf("user_type")
lcLogo = loJResp.StringOf("logo")
lnPoints = loJResp.IntOf("points")
lcSite_id = loJResp.StringOf("site_id")
lcPermalink = loJResp.StringOf("permalink")
lcSeller_reputationLevel_id = loJResp.StringOf("seller_reputation.level_id")
lcSeller_reputationPower_seller_status = loJResp.StringOf("seller_reputation.power_seller_status")
lcSeller_reputationTransactionsPeriod = loJResp.StringOf("seller_reputation.transactions.period")
lnSeller_reputationTransactionsTotal = loJResp.IntOf("seller_reputation.transactions.total")
lnSeller_reputationTransactionsCompleted = loJResp.IntOf("seller_reputation.transactions.completed")
lnSeller_reputationTransactionsCanceled = loJResp.IntOf("seller_reputation.transactions.canceled")
lnSeller_reputationTransactionsRatingsPositive = loJResp.IntOf("seller_reputation.transactions.ratings.positive")
lnSeller_reputationTransactionsRatingsNegative = loJResp.IntOf("seller_reputation.transactions.ratings.negative")
lnSeller_reputationTransactionsRatingsNeutral = loJResp.IntOf("seller_reputation.transactions.ratings.neutral")
lcStatusSite_status = loJResp.StringOf("status.site_status")
i = 0
lnCount_i = loJResp.SizeOfArray("tags")
DO WHILE i < lnCount_i
    loJResp.I = i
    lcStrVal = loJResp.StringOf("tags[i]")
    i = i + 1
ENDDO
i = 0
lnCount_i = loJResp.SizeOfArray("buyer_reputation.tags")
DO WHILE i < lnCount_i
    loJResp.I = i
    i = i + 1
ENDDO

RELEASE loHttp
RELEASE loJsonToken
RELEASE loSbResponseBody
RELEASE loJResp