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"
LOCAL loRest
LOCAL lnSuccess
LOCAL lnBTls
LOCAL lnPort
LOCAL lnBAutoReconnect
LOCAL loSbResponseBody
LOCAL lnRespStatusCode
LOCAL loJsonResponse
LOCAL i
LOCAL lnCount_i
LOCAL lcId
LOCAL lcName
LOCAL lcMessageListVisibility
LOCAL lcLabelListVisibility
LOCAL lcType
loRest = CreateObject('Chilkat_9_5_0.Rest')
* URL: https://www.googleapis.com/gmail/v1/users/me/labels
lnBTls = 1
lnPort = 443
lnBAutoReconnect = 1
lnSuccess = loRest.Connect("www.googleapis.com",lnPort,lnBTls,lnBAutoReconnect)
IF (lnSuccess <> 1) THEN
? "ConnectFailReason: " + STR(loRest.ConnectFailReason)
? loRest.LastErrorText
RELEASE loRest
CANCEL
ENDIF
loRest.AddHeader("Authorization","Bearer GMAIL_TOKEN")
loSbResponseBody = CreateObject('Chilkat_9_5_0.StringBuilder')
lnSuccess = loRest.FullRequestNoBodySb("GET","/gmail/v1/users/me/labels",loSbResponseBody)
IF (lnSuccess <> 1) THEN
? loRest.LastErrorText
RELEASE loRest
RELEASE loSbResponseBody
CANCEL
ENDIF
lnRespStatusCode = loRest.ResponseStatusCode
IF (lnRespStatusCode >= 400) THEN
? "Response Status Code = " + STR(lnRespStatusCode)
? "Response Header:"
? loRest.ResponseHeader
? "Response Body:"
? loSbResponseBody.GetAsString()
RELEASE loRest
RELEASE loSbResponseBody
CANCEL
ENDIF
loJsonResponse = CreateObject('Chilkat_9_5_0.JsonObject')
loJsonResponse.LoadSb(loSbResponseBody)
* See the Online Tool for Generating JSON Parse Code
i = 0
lnCount_i = loJsonResponse.SizeOfArray("labels")
DO WHILE i < lnCount_i
loJsonResponse.I = i
lcId = loJsonResponse.StringOf("labels[i].id")
lcName = loJsonResponse.StringOf("labels[i].name")
lcMessageListVisibility = loJsonResponse.StringOf("labels[i].messageListVisibility")
lcLabelListVisibility = loJsonResponse.StringOf("labels[i].labelListVisibility")
lcType = loJsonResponse.StringOf("labels[i].type")
i = i + 1
ENDDO
RELEASE loRest
RELEASE loSbResponseBody
RELEASE loJsonResponse
{
"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"
}
]
}