(PureBasic) MercadoLibre - GET Request with Access Token in Query Params
Demonstrates how to send an HTTPS GET request to MercadoLibre with the access token specified as a query parameter.
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
Procedure ChilkatExample()
; This example assumes the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
; First get our previously obtained OAuth2 access token.
jsonToken.i = CkJsonObject::ckCreate()
If jsonToken.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
success.i = CkJsonObject::ckLoadFile(jsonToken,"qa_data/tokens/mercadolibre.json")
If success = 0
Debug "Failed to load JSON access token."
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonToken)
ProcedureReturn
EndIf
; Use your seller ID.
CkHttp::ckSetUrlVar(http,"SELLER_ID","577815702")
CkHttp::ckSetUrlVar(http,"ACCESS_TOKEN",CkJsonObject::ckStringOf(jsonToken,"access_token"))
responseStr.s = CkHttp::ckQuickGetStr(http,"https://api.mercadolibre.com/questions/search?seller_id={$SELLER_ID}&api_version=4&access_token={$ACCESS_TOKEN}")
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonToken)
ProcedureReturn
EndIf
Debug responseStr
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(jsonToken)
ProcedureReturn
EndProcedure
|