Lists all labels in the user's mailbox.
curl -X GET https://www.googleapis.com/gmail/v1/users/me/labels \
--header "Authorization: Bearer GMAIL_TOKEN"
#include <CkRestW.h>
#include <CkStringBuilderW.h>
#include <CkJsonObjectW.h>
void ChilkatSample(void)
{
CkRestW rest;
bool success;
// URL: https://www.googleapis.com/gmail/v1/users/me/labels
bool bTls = true;
int port = 443;
bool bAutoReconnect = true;
success = rest.Connect(L"www.googleapis.com",port,bTls,bAutoReconnect);
if (success != true) {
wprintf(L"ConnectFailReason: %d\n",rest.get_ConnectFailReason());
wprintf(L"%s\n",rest.lastErrorText());
return;
}
rest.AddHeader(L"Authorization",L"Bearer GMAIL_TOKEN");
CkStringBuilderW sbResponseBody;
success = rest.FullRequestNoBodySb(L"GET",L"/gmail/v1/users/me/labels",sbResponseBody);
if (success != true) {
wprintf(L"%s\n",rest.lastErrorText());
return;
}
int respStatusCode = rest.get_ResponseStatusCode();
if (respStatusCode >= 400) {
wprintf(L"Response Status Code = %d\n",respStatusCode);
wprintf(L"Response Header:\n");
wprintf(L"%s\n",rest.responseHeader());
wprintf(L"Response Body:\n");
wprintf(L"%s\n",sbResponseBody.getAsString());
return;
}
CkJsonObjectW jsonResponse;
jsonResponse.LoadSb(sbResponseBody);
// See the Online Tool for Generating JSON Parse Code
int i;
int count_i;
i = 0;
count_i = jsonResponse.SizeOfArray(L"labels");
while (i < count_i) {
jsonResponse.put_I(i);
const wchar_t *id = jsonResponse.stringOf(L"labels[i].id");
const wchar_t *name = jsonResponse.stringOf(L"labels[i].name");
const wchar_t *messageListVisibility = jsonResponse.stringOf(L"labels[i].messageListVisibility");
const wchar_t *labelListVisibility = jsonResponse.stringOf(L"labels[i].labelListVisibility");
const wchar_t *type = jsonResponse.stringOf(L"labels[i].type");
i = i + 1;
}
}
{
"labels": [
{
"id": "Label_5",
"name": "QA",
"messageListVisibility": "show",
"labelListVisibility": "labelShow",
"type": "user"
},
{
"id": "Label_21",
"name": "[Gmail]/testFolder",
"type": "user"
},
{
"id": "CATEGORY_PERSONAL",
"name": "CATEGORY_PERSONAL",
"type": "system"
},
{
"id": "Label_8",
"name": "old",
"type": "user"
},
{
"id": "CATEGORY_SOCIAL",
"name": "CATEGORY_SOCIAL",
"type": "system"
},
{
"id": "Label_7",
"name": "labél with space",
"type": "user"
},
{
"id": "Label_41",
"name": "QA/qa_fetchSingleAsMime",
"type": "user"
},
{
"id": "Label_4",
"name": "[Imap]/Trash",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "user"
},
{
"id": "Label_1",
"name": "\"test\"",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "user"
},
{
"id": "Label_6",
"name": "QA/Entwürfe",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "user"
},
{
"id": "CATEGORY_FORUMS",
"name": "CATEGORY_FORUMS",
"type": "system"
},
{
"id": "Label_42",
"name": "[Gmail]/フルタイムの共有ソリューションはjapan",
"type": "user"
},
{
"id": "Label_3",
"name": "[Gmail]/ö",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "user"
},
{
"id": "IMPORTANT",
"name": "IMPORTANT",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "system"
},
{
"id": "Label_2",
"name": "[Gmail]/X&Y",
"type": "user"
},
{
"id": "CATEGORY_UPDATES",
"name": "CATEGORY_UPDATES",
"type": "system"
},
{
"id": "CHAT",
"name": "CHAT",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "system"
},
{
"id": "SENT",
"name": "SENT",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "system"
},
{
"id": "INBOX",
"name": "INBOX",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "system"
},
{
"id": "TRASH",
"name": "TRASH",
"messageListVisibility": "hide",
"labelListVisibility": "labelHide",
"type": "system"
},
{
"id": "CATEGORY_PROMOTIONS",
"name": "CATEGORY_PROMOTIONS",
"type": "system"
},
{
"id": "DRAFT",
"name": "DRAFT",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "system"
},
{
"id": "SPAM",
"name": "SPAM",
"messageListVisibility": "hide",
"labelListVisibility": "labelHide",
"type": "system"
},
{
"id": "STARRED",
"name": "STARRED",
"messageListVisibility": "hide",
"labelListVisibility": "labelShow",
"type": "system"
},
{
"id": "UNREAD",
"name": "UNREAD",
"type": "system"
}
]
}