Sample code for 30+ languages & platforms
PureBasic

BrickLink OAuth1 using Chilkat REST

See more BrickLink Examples

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).

Chilkat PureBasic Downloads

PureBasic
IncludeFile "CkStringBuilder.pb"
IncludeFile "CkRest.pb"
IncludeFile "CkJsonObject.pb"
IncludeFile "CkOAuth1.pb"

Procedure ChilkatExample()

    success.i = 0

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

    oauth1.i = CkOAuth1::ckCreate()
    If oauth1.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkOAuth1::setCkConsumerKey(oauth1, "Your Consumer Key")
    CkOAuth1::setCkConsumerSecret(oauth1, "Your Consumer Secret")
    CkOAuth1::setCkToken(oauth1, "Your OAuth1 Token")
    CkOAuth1::setCkTokenSecret(oauth1, "Your Token Secret")
    CkOAuth1::setCkSignatureMethod(oauth1, "HMAC-SHA1")

    rest.i = CkRest::ckCreate()
    If rest.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkRest::ckSetAuthOAuth1(rest,oauth1,0)

    success = CkRest::ckConnect(rest,"api.bricklink.com",443,1,1)
    If success = 0
        Debug CkRest::ckLastErrorText(rest)
        CkOAuth1::ckDispose(oauth1)
        CkRest::ckDispose(rest)
        ProcedureReturn
    EndIf

    sbResponse.i = CkStringBuilder::ckCreate()
    If sbResponse.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    success = CkRest::ckFullRequestNoBodySb(rest,"GET","/api/store/v1/orders?direction=in",sbResponse)
    If success = 0
        Debug CkRest::ckLastErrorText(rest)
        CkOAuth1::ckDispose(oauth1)
        CkRest::ckDispose(rest)
        CkStringBuilder::ckDispose(sbResponse)
        ProcedureReturn
    EndIf

    Debug "Response status code = " + Str(CkRest::ckResponseStatusCode(rest))

    json.i = CkJsonObject::ckCreate()
    If json.i = 0
        Debug "Failed to create object."
        ProcedureReturn
    EndIf

    CkJsonObject::ckLoadSb(json,sbResponse)
    CkJsonObject::setCkEmitCompact(json, 0)
    Debug CkJsonObject::ckEmit(json)


    CkOAuth1::ckDispose(oauth1)
    CkRest::ckDispose(rest)
    CkStringBuilder::ckDispose(sbResponse)
    CkJsonObject::ckDispose(json)


    ProcedureReturn
EndProcedure