(Tcl) BrickLink OAuth1 using Chilkat REST
Demonstrates sending an api.bricklink.com request with OAuth1 authentication using Chilkat REST.
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
load ./chilkat.dll
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
set oauth1 [new_CkOAuth1]
CkOAuth1_put_ConsumerKey $oauth1 "Your Consumer Key"
CkOAuth1_put_ConsumerSecret $oauth1 "Your Consumer Secret"
CkOAuth1_put_Token $oauth1 "Your OAuth1 Token"
CkOAuth1_put_TokenSecret $oauth1 "Your Token Secret"
CkOAuth1_put_SignatureMethod $oauth1 "HMAC-SHA1"
set rest [new_CkRest]
CkRest_SetAuthOAuth1 $rest $oauth1 0
set success [CkRest_Connect $rest "api.bricklink.com" 443 1 1]
if {$success == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkOAuth1 $oauth1
delete_CkRest $rest
exit
}
set sbResponse [new_CkStringBuilder]
set success [CkRest_FullRequestNoBodySb $rest "GET" "/api/store/v1/orders?direction=in" $sbResponse]
if {$success == 0} then {
puts [CkRest_lastErrorText $rest]
delete_CkOAuth1 $oauth1
delete_CkRest $rest
delete_CkStringBuilder $sbResponse
exit
}
puts "Response status code = [CkRest_get_ResponseStatusCode $rest]"
set json [new_CkJsonObject]
CkJsonObject_LoadSb $json $sbResponse
CkJsonObject_put_EmitCompact $json 0
puts [CkJsonObject_emit $json]
delete_CkOAuth1 $oauth1
delete_CkRest $rest
delete_CkStringBuilder $sbResponse
delete_CkJsonObject $json
|