Unicode C
Unicode C
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 Unicode C Downloads
#include <C_CkOAuth1W.h>
#include <C_CkRestW.h>
#include <C_CkStringBuilderW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkOAuth1W oauth1;
HCkRestW rest;
HCkStringBuilderW sbResponse;
HCkJsonObjectW json;
success = FALSE;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oauth1 = CkOAuth1W_Create();
CkOAuth1W_putConsumerKey(oauth1,L"Your Consumer Key");
CkOAuth1W_putConsumerSecret(oauth1,L"Your Consumer Secret");
CkOAuth1W_putToken(oauth1,L"Your OAuth1 Token");
CkOAuth1W_putTokenSecret(oauth1,L"Your Token Secret");
CkOAuth1W_putSignatureMethod(oauth1,L"HMAC-SHA1");
rest = CkRestW_Create();
CkRestW_SetAuthOAuth1(rest,oauth1,FALSE);
success = CkRestW_Connect(rest,L"api.bricklink.com",443,TRUE,TRUE);
if (success == FALSE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkOAuth1W_Dispose(oauth1);
CkRestW_Dispose(rest);
return;
}
sbResponse = CkStringBuilderW_Create();
success = CkRestW_FullRequestNoBodySb(rest,L"GET",L"/api/store/v1/orders?direction=in",sbResponse);
if (success == FALSE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkOAuth1W_Dispose(oauth1);
CkRestW_Dispose(rest);
CkStringBuilderW_Dispose(sbResponse);
return;
}
wprintf(L"Response status code = %d\n",CkRestW_getResponseStatusCode(rest));
json = CkJsonObjectW_Create();
CkJsonObjectW_LoadSb(json,sbResponse);
CkJsonObjectW_putEmitCompact(json,FALSE);
wprintf(L"%s\n",CkJsonObjectW_emit(json));
CkOAuth1W_Dispose(oauth1);
CkRestW_Dispose(rest);
CkStringBuilderW_Dispose(sbResponse);
CkJsonObjectW_Dispose(json);
}