(PureBasic) BrickLink OAuth1 using Chilkat HTTP
Demonstrates sending an api.bricklink.com request with OAuth1 authentication using Chilkat HTTP.
Note: This example requires Chilkat v9.5.0.91 or greater (due to adjustments made within Chilkat to support bricklink OAuth1 needs). For more information, see https://www.bricklink.com/v3/api.page?page=auth
IncludeFile "CkHttpResponse.pb"
IncludeFile "CkHttp.pb"
IncludeFile "CkJsonObject.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
CkHttp::setCkOAuth1(http, 1)
CkHttp::setCkOAuthConsumerKey(http, "Your Consumer Key")
CkHttp::setCkOAuthConsumerSecret(http, "Your Consumer Secret")
CkHttp::setCkOAuthToken(http, "Your OAuth1 Token")
CkHttp::setCkOAuthTokenSecret(http, "Your Token Secret")
CkHttp::setCkOAuthSigMethod(http, "HMAC-SHA1")
resp.i = CkHttp::ckQuickGetObj(http,"https://api.bricklink.com/api/store/v1/orders?direction=in")
If CkHttp::ckLastMethodSuccess(http) = 0
Debug CkHttp::ckLastErrorText(http)
CkHttp::ckDispose(http)
ProcedureReturn
EndIf
Debug "Response status code = " + Str(CkHttpResponse::ckStatusCode(resp))
json.i = CkJsonObject::ckCreate()
If json.i = 0
Debug "Failed to create object."
ProcedureReturn
EndIf
CkHttpResponse::ckGetBodyJson(resp,json)
CkHttpResponse::ckDispose(resp)
CkJsonObject::setCkEmitCompact(json, 0)
Debug CkJsonObject::ckEmit(json)
CkHttp::ckDispose(http)
CkJsonObject::ckDispose(json)
ProcedureReturn
EndProcedure
|