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 <CkHttpW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>

void ChilkatSample(void)
    {
    bool success = false;

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

    CkHttpW http;
    http.put_AuthToken(L"GMAIL-ACCESS-TOKEN");

    const wchar_t *userId = L"me";
    http.SetUrlVar(L"userId",userId);

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

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

    // Get the list of GMail labels as JSON.
    CkStringBuilderW sb;
    success = http.QuickGetSb(url,sb);
    if (success != true) {
        wprintf(L"%s\n",http.lastErrorText());
        return;
    }

    CkJsonObjectW json;
    json.LoadSb(sb);
    json.put_EmitCompact(false);
    wprintf(L"%s\n",json.emit());

    if (http.get_LastStatus() != 200) {
        wprintf(L"Failed.\n");
        return;
    }
    }