Sample code for 30+ languages & platforms
Unicode C

List all Labels in the User's Mailbox

See more GMail REST API Examples

List all Labels in the GMail User's Mailbox

Chilkat Unicode C Downloads

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

void ChilkatSample(void)
    {
    BOOL success;
    HCkHttpW http;
    const wchar_t *userId;
    const wchar_t *url;
    HCkStringBuilderW sb;
    HCkJsonObjectW json;

    success = FALSE;

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

    http = CkHttpW_Create();
    CkHttpW_putAuthToken(http,L"GMAIL-ACCESS-TOKEN");

    userId = L"me";
    CkHttpW_SetUrlVar(http,L"userId",userId);

    url = L"https://www.googleapis.com/gmail/v1/users/{$userId}/labels";

    CkHttpW_putSessionLogFilename(http,L"c:/temp/qa_output/sessionLog.txt");

    // Get the list of GMail labels as JSON.
    sb = CkStringBuilderW_Create();
    success = CkHttpW_QuickGetSb(http,url,sb);
    if (success != TRUE) {
        wprintf(L"%s\n",CkHttpW_lastErrorText(http));
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sb);
        return;
    }

    json = CkJsonObjectW_Create();
    CkJsonObjectW_LoadSb(json,sb);
    CkJsonObjectW_putEmitCompact(json,FALSE);
    wprintf(L"%s\n",CkJsonObjectW_emit(json));

    if (CkHttpW_getLastStatus(http) != 200) {
        wprintf(L"Failed.\n");
        CkHttpW_Dispose(http);
        CkStringBuilderW_Dispose(sb);
        CkJsonObjectW_Dispose(json);
        return;
    }



    CkHttpW_Dispose(http);
    CkStringBuilderW_Dispose(sb);
    CkJsonObjectW_Dispose(json);

    }