Sample code for 30+ languages & platforms
Java

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 Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.OAuth1;
import com.chilkatsoft.chilkat2.Rest;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example assumes the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        OAuth1 oauth1 = new OAuth1();

        oauth1.setConsumerKey("Your Consumer Key");
        oauth1.setConsumerSecret("Your Consumer Secret");
        oauth1.setToken("Your OAuth1 Token");
        oauth1.setTokenSecret("Your Token Secret");
        oauth1.setSignatureMethod("HMAC-SHA1");

        Rest rest = new Rest();

        rest.setAuthOAuth1(oauth1, false);

        try {
            rest.connect("api.bricklink.com", 443, true, true);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        StringBuilder sbResponse = new StringBuilder();
        try {
            rest.fullRequestNoBodySb("GET", "/api/store/v1/orders?direction=in", sbResponse);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        System.out.println("Response status code = " + rest.getResponseStatusCode());

        JsonObject json = new JsonObject();
        json.loadSb(sbResponse);
        json.setEmitCompact(false);
        System.out.println(json.emit());
    }
}