Visual FoxPro Requires Chilkat v11.0.0+
Visual FoxPro
Find a Gmail label ID by name
See more GMail REST API Examples
Look up a label using its exact display name, including any parent/child path. Labels and their IDs belong to the authenticated mailbox. Use Gmail’s returned ID when applying a user label to messages.
Authorize the application with https://www.googleapis.com/auth/gmail.labels. The example reads the access token from gmail-token.json in a private working directory. Authorize a desktop application.
Chilkat Visual FoxPro Downloads
LOCAL lnSuccess
LOCAL loToken
LOCAL loHttp
LOCAL loResp
LOCAL loReply
LOCAL loLabel
lnSuccess = 0
* Assumes Chilkat is unlocked. See Global Unlock Sample.
loToken = CreateObject('Chilkat.JsonObject')
lnSuccess = loToken.LoadFile("gmail-token.json")
IF (lnSuccess <> 1) THEN
? "Could not read gmail-token.json from the private working directory."
RELEASE loToken
CANCEL
ENDIF
IF ((loToken.JsonTypeOf("access_token") <> 1) OR (loToken.StringOfEquals("access_token","",1) = 1)) THEN
? "An OAuth access token is required."
RELEASE loToken
CANCEL
ENDIF
loHttp = CreateObject('Chilkat.Http')
loHttp.RequireSslCertVerify = 1
loHttp.AuthToken = loToken.StringOf("access_token")
loResp = CreateObject('Chilkat.HttpResponse')
loReply = CreateObject('Chilkat.JsonObject')
lnSuccess = loHttp.HttpNoBody("GET","https://gmail.googleapis.com/gmail/v1/users/me/labels",loResp)
IF (loResp.StatusCode = 0) THEN
? "Gmail did not return an HTTP response."
RELEASE loToken
RELEASE loHttp
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
IF ((lnSuccess <> 1) OR (loResp.StatusCode < 200) OR (loResp.StatusCode >= 300)) THEN
? "Gmail HTTP " + STR(loResp.StatusCode)
lnSuccess = loReply.Load(loResp.BodyStr)
IF (lnSuccess = 1) THEN
? loReply.StringOf("error.message")
ENDIF
RELEASE loToken
RELEASE loHttp
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
lnSuccess = loReply.Load(loResp.BodyStr)
IF (lnSuccess <> 1) THEN
? "Expected a Gmail JSON response."
RELEASE loToken
RELEASE loHttp
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
IF (loReply.JsonTypeOf("labels") <> 4) THEN
? "Expected a list of labels."
RELEASE loToken
RELEASE loHttp
RELEASE loResp
RELEASE loReply
CANCEL
ENDIF
loLabel = CreateObject('Chilkat.JsonObject')
lnSuccess = loReply.FindRecord2("labels","name","To review",1,loLabel)
IF (lnSuccess <> 1) THEN
? "No label with that exact name. Check the name or create the label first."
RELEASE loToken
RELEASE loHttp
RELEASE loResp
RELEASE loReply
RELEASE loLabel
CANCEL
ENDIF
? "Label ID: " + loLabel.StringOf("id")
RELEASE loToken
RELEASE loHttp
RELEASE loResp
RELEASE loReply
RELEASE loLabel