Sample code for 30+ languages & platforms
Unicode C

BrickLink OAuth1 using Chilkat HTTP

See more BrickLink Examples

Demonstrates sending an api.bricklink.com request with OAuth1 authentication using Chilkat HTTP.

Chilkat Unicode C Downloads

Unicode C
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>
#include <C_CkJsonObjectW.h>

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    HCkHttpResponseW resp;
    HCkJsonObjectW json;

    success = FALSE;

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

    http = CkHttpW_Create();

    CkHttpW_putOAuth1(http,TRUE);
    CkHttpW_putOAuthConsumerKey(http,L"Your Consumer Key");
    CkHttpW_putOAuthConsumerSecret(http,L"Your Consumer Secret");
    CkHttpW_putOAuthToken(http,L"Your OAuth1 Token");
    CkHttpW_putOAuthTokenSecret(http,L"Your Token Secret");
    CkHttpW_putOAuthSigMethod(http,L"HMAC-SHA1");

    resp = CkHttpResponseW_Create();
    success = CkHttpW_HttpNoBody(http,L"GET",L"https://api.bricklink.com/api/store/v1/orders?direction=in",resp);
    if (success == FALSE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkHttpResponseW_Dispose(resp);
        return;
    }

    wprintf(L"Response status code = %d\n",CkHttpResponseW_getStatusCode(resp));

    json = CkJsonObjectW_Create();
    CkHttpResponseW_GetBodyJson(resp,json);

    CkJsonObjectW_putEmitCompact(json,FALSE);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));


    CkHttpW_Dispose(http);
    CkHttpResponseW_Dispose(resp);
    CkJsonObjectW_Dispose(json);

    }