(PureBasic) Magento Request with OAuth1.0a Authentication
Demonstrates sending a Magento request with OAuth1.0a authentication. (Using the Magento 1.x REST API)
IncludeFile "CkJsonObject.pb"
IncludeFile "CkHttp.pb"
Procedure ChilkatExample()
; This example requires the Chilkat API to have been previously unlocked.
; See Global Unlock Sample for sample code.
success.i
http.i = CkHttp::ckCreate()
If http.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkHttp::setCkOAuth1(http, 1)
CkHttp::setCkOAuthVerifier(http, "")
CkHttp::setCkOAuthConsumerKey(http, "MAGENTO_CONSUMER_KEY")
CkHttp::setCkOAuthConsumerSecret(http, "MAGENTO_CONSUMER_SECRET")
CkHttp::setCkOAuthToken(http, "MAGENTO__TOKEN")
CkHttp::setCkOAuthTokenSecret(http, "MAGENTO_TOKEN_SECRET")
CkHttp::setCkAccept(http, "application/json")
url.s = "http://www.inart.com/api/rest/products/store/2?limit=20&page=1"
jsonStr.s = CkHttp::ckQuickGetStr(http,url)
If CkHttp::ckLastMethodSuccess(http) <> 1
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
ProcedureReturn
EndIf
Debug "Response status code = " + Str(CkHttp::ckLastStatus(http))
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkJsonObject::ckLoad(json,jsonStr)
CkJsonObject::setCkEmitCompact(json, 0)
Debug CkJsonObject::ckEmit(json)
; Use this online tool to generate parsing code from sample JSON:
; Generate Parsing Code from JSON
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure
|