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"
integer li_rc
oleobject loo_Rest
integer li_Success
integer li_BTls
integer li_Port
integer li_BAutoReconnect
oleobject loo_SbResponseBody
integer li_RespStatusCode
oleobject loo_JsonResponse
integer i
integer li_Count_i
string ls_Id
string ls_Name
string ls_MessageListVisibility
string ls_LabelListVisibility
string ls_Type
loo_Rest = create oleobject
li_rc = loo_Rest.ConnectToNewObject("Chilkat_9_5_0.Rest")
if li_rc < 0 then
destroy loo_Rest
MessageBox("Error","Connecting to COM object failed")
return
end if
// URL: https://www.googleapis.com/gmail/v1/users/me/labels
li_BTls = 1
li_Port = 443
li_BAutoReconnect = 1
li_Success = loo_Rest.Connect("www.googleapis.com",li_Port,li_BTls,li_BAutoReconnect)
if li_Success <> 1 then
Write-Debug "ConnectFailReason: " + string(loo_Rest.ConnectFailReason)
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
return
end if
loo_Rest.AddHeader("Authorization","Bearer GMAIL_TOKEN")
loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat_9_5_0.StringBuilder")
li_Success = loo_Rest.FullRequestNoBodySb("GET","/gmail/v1/users/me/labels",loo_SbResponseBody)
if li_Success <> 1 then
Write-Debug loo_Rest.LastErrorText
destroy loo_Rest
destroy loo_SbResponseBody
return
end if
li_RespStatusCode = loo_Rest.ResponseStatusCode
if li_RespStatusCode >= 400 then
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
Write-Debug "Response Header:"
Write-Debug loo_Rest.ResponseHeader
Write-Debug "Response Body:"
Write-Debug loo_SbResponseBody.GetAsString()
destroy loo_Rest
destroy loo_SbResponseBody
return
end if
loo_JsonResponse = create oleobject
li_rc = loo_JsonResponse.ConnectToNewObject("Chilkat_9_5_0.JsonObject")
loo_JsonResponse.LoadSb(loo_SbResponseBody)
// See the Online Tool for Generating JSON Parse Code
i = 0
li_Count_i = loo_JsonResponse.SizeOfArray("labels")
do while i < li_Count_i
loo_JsonResponse.I = i
ls_Id = loo_JsonResponse.StringOf("labels[i].id")
ls_Name = loo_JsonResponse.StringOf("labels[i].name")
ls_MessageListVisibility = loo_JsonResponse.StringOf("labels[i].messageListVisibility")
ls_LabelListVisibility = loo_JsonResponse.StringOf("labels[i].labelListVisibility")
ls_Type = loo_JsonResponse.StringOf("labels[i].type")
i = i + 1
loop
destroy loo_Rest
destroy loo_SbResponseBody
destroy loo_JsonResponse
{
"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"
}
]
}