Unicode C
Unicode C
Dropbox: Get Space Usage
See more Dropbox Examples
Demonstrates how to get the Dropbox space usage information for the current user's account.Chilkat Unicode C Downloads
#include <C_CkRestW.h>
#include <C_CkJsonObjectW.h>
void ChilkatSample(void)
{
BOOL success;
HCkRestW rest;
BOOL bTls;
int port;
BOOL bAutoReconnect;
const wchar_t *responseStr;
HCkJsonObjectW jsonResponse;
success = FALSE;
// This example requires the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
rest = CkRestW_Create();
// Connect to the www.dropbox.com endpoint.
bTls = TRUE;
port = 443;
bAutoReconnect = TRUE;
success = CkRestW_Connect(rest,L"api.dropboxapi.com",port,bTls,bAutoReconnect);
if (success != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
CkRestW_AddHeader(rest,L"Authorization",L"Bearer DROPBOX-ACCESS-TOKEN");
responseStr = CkRestW_fullRequestNoBody(rest,L"POST",L"/2/users/get_space_usage");
if (CkRestW_getLastMethodSuccess(rest) != TRUE) {
wprintf(L"%s\n",CkRestW_lastErrorText(rest));
CkRestW_Dispose(rest);
return;
}
// Success is indicated by a 200 response status code.
if (CkRestW_getResponseStatusCode(rest) != 200) {
// Examine the request/response to see what happened.
wprintf(L"response status code = %d\n",CkRestW_getResponseStatusCode(rest));
wprintf(L"response status text = %s\n",CkRestW_responseStatusText(rest));
wprintf(L"response header: %s\n",CkRestW_responseHeader(rest));
wprintf(L"response body (if any): %s\n",responseStr);
wprintf(L"---\n");
wprintf(L"LastRequestStartLine: %s\n",CkRestW_lastRequestStartLine(rest));
wprintf(L"LastRequestHeader: %s\n",CkRestW_lastRequestHeader(rest));
CkRestW_Dispose(rest);
return;
}
jsonResponse = CkJsonObjectW_Create();
CkJsonObjectW_Load(jsonResponse,responseStr);
CkJsonObjectW_putEmitCompact(jsonResponse,FALSE);
wprintf(L"%s\n",CkJsonObjectW_emit(jsonResponse));
// {
// "used": 3032115,
// "allocation": {
// ".tag": "individual",
// "allocated": 2147483648
// }
// }
//
CkRestW_Dispose(rest);
CkJsonObjectW_Dispose(jsonResponse);
}