Gets a specific message using format=full.
Use ChilkatAx-9.5.0-win32.pkg
Procedure Test
Handle hoRest
Boolean iSuccess
Variant vOauth2
Handle hoOauth2
Variant vSbJson
Handle hoSbJson
Handle hoJson
String sId
String sThreadId
String sSnippet
String sHistoryId
String sInternalDate
String sPayloadPartId
String sPayloadMimeType
String sPayloadFilename
Integer iPayloadBodySize
Integer iSizeEstimate
Integer i
Integer iCount_i
String sStrVal
String sName
String sValue
String sPartId
String sMimeType
String sFilename
Integer iBodySize
String sBodyAttachmentId
Integer j
Integer iCount_j
Integer k
Integer iCount_k
String sBodyData
Integer iI1
Integer iCount_i1
Variant vJson1
Handle hoJson1
String sTemp1
Integer iTemp1
Get Create (RefClass(cComChilkatRest)) To hoRest
If (Not(IsComObjectCreated(hoRest))) Begin
Send CreateComObject of hoRest
End
// Provide a previously obtained OAuth2 access token.
Get Create (RefClass(cComChilkatOAuth2)) To hoOauth2
If (Not(IsComObjectCreated(hoOauth2))) Begin
Send CreateComObject of hoOauth2
End
Set ComAccessToken Of hoOauth2 To "OAUTH2_ACCESS_TOKEN"
Get pvComObject of hoOauth2 to vOauth2
Get ComSetAuthOAuth2 Of hoRest vOauth2 To iSuccess
Get ComConnect Of hoRest "www.googleapis.com" 443 True True To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComAddPathParam Of hoRest "messageId" "15fc23688c553739" To iSuccess
Get ComAddQueryParam Of hoRest "format" "full" To iSuccess
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbJson
If (Not(IsComObjectCreated(hoSbJson))) Begin
Send CreateComObject of hoSbJson
End
Get pvComObject of hoSbJson to vSbJson
Get ComFullRequestNoBodySb Of hoRest "GET" "/gmail/v1/users/me/messages/messageId" vSbJson To iSuccess
If (iSuccess <> True) Begin
Get ComLastErrorText Of hoRest To sTemp1
Showln sTemp1
Procedure_Return
End
Get ComResponseStatusCode Of hoRest To iTemp1
If (iTemp1 <> 200) Begin
Get ComResponseStatusCode Of hoRest To iTemp1
Showln "Received error response code: " iTemp1
Showln "Response body:"
Get ComGetAsString Of hoSbJson To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get pvComObject of hoSbJson to vSbJson
Get ComLoadSb Of hoJson vSbJson To iSuccess
// The following code parses the JSON response.
// A sample JSON response is shown below the sample code.
Get ComStringOf Of hoJson "id" To sId
Get ComStringOf Of hoJson "threadId" To sThreadId
Get ComStringOf Of hoJson "snippet" To sSnippet
Get ComStringOf Of hoJson "historyId" To sHistoryId
Get ComStringOf Of hoJson "internalDate" To sInternalDate
Get ComStringOf Of hoJson "payload.partId" To sPayloadPartId
Get ComStringOf Of hoJson "payload.mimeType" To sPayloadMimeType
Get ComStringOf Of hoJson "payload.filename" To sPayloadFilename
Get ComIntOf Of hoJson "payload.body.size" To iPayloadBodySize
Get ComIntOf Of hoJson "sizeEstimate" To iSizeEstimate
Move 0 To i
Get ComSizeOfArray Of hoJson "labelIds" To iCount_i
While (i < iCount_i)
Set ComI Of hoJson To i
Get ComStringOf Of hoJson "labelIds[i]" To sStrVal
Move i + 1 To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJson "payload.headers" To iCount_i
While (i < iCount_i)
Set ComI Of hoJson To i
Get ComStringOf Of hoJson "payload.headers[i].name" To sName
Get ComStringOf Of hoJson "payload.headers[i].value" To sValue
Move i + 1 To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJson "payload.parts" To iCount_i
While (i < iCount_i)
Set ComI Of hoJson To i
Get ComStringOf Of hoJson "payload.parts[i].partId" To sPartId
Get ComStringOf Of hoJson "payload.parts[i].mimeType" To sMimeType
Get ComStringOf Of hoJson "payload.parts[i].filename" To sFilename
Get ComIntOf Of hoJson "payload.parts[i].body.size" To iBodySize
Get ComStringOf Of hoJson "payload.parts[i].body.attachmentId" To sBodyAttachmentId
Move 0 To j
Get ComSizeOfArray Of hoJson "payload.parts[i].headers" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJson To j
Get ComStringOf Of hoJson "payload.parts[i].headers[j].name" To sName
Get ComStringOf Of hoJson "payload.parts[i].headers[j].value" To sValue
Move j + 1 To j
Loop
Move 0 To j
Get ComSizeOfArray Of hoJson "payload.parts[i].parts" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJson To j
Get ComStringOf Of hoJson "payload.parts[i].parts[j].partId" To sPartId
Get ComStringOf Of hoJson "payload.parts[i].parts[j].mimeType" To sMimeType
Get ComStringOf Of hoJson "payload.parts[i].parts[j].filename" To sFilename
Get ComIntOf Of hoJson "payload.parts[i].parts[j].body.size" To iBodySize
Get ComStringOf Of hoJson "payload.parts[i].parts[j].body.attachmentId" To sBodyAttachmentId
Move 0 To k
Get ComSizeOfArray Of hoJson "payload.parts[i].parts[j].headers" To iCount_k
While (k < iCount_k)
Set ComK Of hoJson To k
Get ComStringOf Of hoJson "payload.parts[i].parts[j].headers[k].name" To sName
Get ComStringOf Of hoJson "payload.parts[i].parts[j].headers[k].value" To sValue
Move k + 1 To k
Loop
Move 0 To k
Get ComSizeOfArray Of hoJson "payload.parts[i].parts[j].parts" To iCount_k
While (k < iCount_k)
Set ComK Of hoJson To k
Get ComStringOf Of hoJson "payload.parts[i].parts[j].parts[k].partId" To sPartId
Get ComStringOf Of hoJson "payload.parts[i].parts[j].parts[k].mimeType" To sMimeType
Get ComStringOf Of hoJson "payload.parts[i].parts[j].parts[k].filename" To sFilename
Get ComIntOf Of hoJson "payload.parts[i].parts[j].parts[k].body.size" To iBodySize
Get ComStringOf Of hoJson "payload.parts[i].parts[j].parts[k].body.data" To sBodyData
Get ComObjectOf Of hoJson "payload.parts[i].parts[j].parts[k]" To vJson1
If (IsComObject(vJson1)) Begin
Get Create (RefClass(cComChilkatJsonObject)) To hoJson1
Set pvComObject Of hoJson1 To vJson1
End
Move 0 To iI1
Get ComSizeOfArray Of hoJson1 "headers" To iCount_i1
While (iI1 < iCount_i1)
Set ComI Of hoJson1 To iI1
Get ComStringOf Of hoJson1 "headers[i].name" To sName
Get ComStringOf Of hoJson1 "headers[i].value" To sValue
Move iI1 + 1 To iI1
Loop
Send Destroy of hoJson1
Move k + 1 To k
Loop
Move j + 1 To j
Loop
Move i + 1 To i
Loop
Showln "Example Completed."
End_Procedure
{
"id": "15fc23688c553739",
"threadId": "15fc23688c553739",
"labelIds": [
"IMPORTANT",
"SENT",
"INBOX"
],
"snippet": "This is a test. \u200b",
"historyId": "1438",
"internalDate": "1510791874000",
"payload": {
"partId": "",
"mimeType": "multipart/mixed",
"filename": "",
"headers": [
{
"name": "MIME-Version",
"value": "1.0"
},
{
"name": "Received",
"value": "by 10.25.23.105 with HTTP; Wed, 15 Nov 2017 16:24:34 -0800 (PST)"
},
{
"name": "X-Originating-IP",
"value": "[2601:249:e00:9093:e894:b27f:e5d6:d01d]"
},
{
"name": "Date",
"value": "Wed, 15 Nov 2017 18:24:34 -0600"
},
{
"name": "Delivered-To",
"value": "matt@chilkat.io"
},
{
"name": "Message-ID",
"value": "\u003cCAPhjyBM1qqXS6NVB65W8Zt5-McF03qWSRDjW5am66wTMuard=w@mail.gmail.com\u003e"
},
{
"name": "Subject",
"value": "Test HTML email with image and attachment."
},
{
"name": "From",
"value": "Matt Fausey \u003cmatt@chilkat.io\u003e"
},
{
"name": "To",
"value": "Matt Fausey \u003cmatt@chilkat.io\u003e"
},
{
"name": "Content-Type",
"value": "multipart/mixed; boundary=\"001a11401a6c097887055e0ea572\""
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0",
"mimeType": "multipart/related",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "multipart/related; boundary=\"001a11401a6c097885055e0ea571\""
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0.0",
"mimeType": "multipart/alternative",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "multipart/alternative; boundary=\"001a11401a6c097882055e0ea570\""
}
],
"body": {
"size": 0
},
"parts": [
{
"partId": "0.0.0",
"mimeType": "text/plain",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/plain; charset=\"UTF-8\""
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 22,
"data": "VGhpcyBpcyBhIHRlc3QuDQrigIsNCg=="
}
},
{
"partId": "0.0.1",
"mimeType": "text/html",
"filename": "",
"headers": [
{
"name": "Content-Type",
"value": "text/html; charset=\"UTF-8\""
},
{
"name": "Content-Transfer-Encoding",
"value": "quoted-printable"
}
],
"body": {
"size": 115,
"data": "PGRpdiBkaXI9Imx0ciI-VGhpcyBpcyBhIHRlc3QuPGltZyB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCIgc3JjPSJjaWQ6aWlfamExcWY5MGwwXzE1ZmMyMzUzOWJkMDA3MjciPjxicj7igIs8L2Rpdj4NCg=="
}
}
]
},
{
"partId": "0.1",
"mimeType": "image/jpeg",
"filename": "starfish.jpg",
"headers": [
{
"name": "Content-Type",
"value": "image/jpeg; name=\"starfish.jpg\""
},
{
"name": "Content-Disposition",
"value": "inline; filename=\"starfish.jpg\""
},
{
"name": "Content-Transfer-Encoding",
"value": "base64"
},
{
"name": "Content-ID",
"value": "\u003cii_ja1qf90l0_15fc23539bd00727\u003e"
},
{
"name": "X-Attachment-Id",
"value": "ii_ja1qf90l0_15fc23539bd00727"
},
{
"name": "MIME-Version",
"value": "1.0"
},
{
"name": "Date",
"value": "Wed, 15 Nov 2017 16:23:08 -0800"
},
{
"name": "Message-ID",
"value": "\u003cCAPhjyBMicJ9k-EXY5Efcvp8o_z_J3x8_G=mnC_znLXnyBogemQ@mail.gmail.com\u003e"
},
{
"name": "Subject",
"value": "Attachment"
},
{
"name": "From",
"value": "Matt Fausey \u003cmatt@chilkat.io\u003e"
}
],
"body": {
"attachmentId": "ANGjdJ_ueuzzM9bpQ8l_tD27oDfn-smCe77viIAF1wy8ZeI09tK5vAuSS6V9Bahow4ikqaGleXqdQBeq8xhFkJ7WN-KKBSKvOfT2yD-XMlA1FC8AOKS2A8tBi5dDDbFrbnns33rfqEIRFAISslhdE481uB6sYfVoYjpuDThtW6Y96YA0Aso0P9txbKJwcwOeD0RxDav_vPzDjHuRuOYsGxbVTxesMB2eiMMw3i1y-WAu-pyWHqF0xMFehZmd7d-krKKdvI4UEgtzD9siXnnaH6MG55ykjBsjFRsmjKc-4K5fHeYHOf586Pkej5K238A",
"size": 6229
}
}
]
},
{
"partId": "1",
"mimeType": "application/pdf",
"filename": "helloWorld.pdf",
"headers": [
{
"name": "Content-Type",
"value": "application/pdf; name=\"helloWorld.pdf\""
},
{
"name": "Content-Disposition",
"value": "attachment; filename=\"helloWorld.pdf\""
},
{
"name": "Content-Transfer-Encoding",
"value": "base64"
},
{
"name": "X-Attachment-Id",
"value": "f_ja1qgya31"
}
],
"body": {
"attachmentId": "ANGjdJ934ScA-kvdsvBvOjO9z-RYmRLyO8PvqOCzwkk-smeLVpKqeoxXNIn9FL_RbzA6qmTWKQTJehrBVmX4NqYtFsivmwRfzIWj-A-SqvJATRhjEGOntUeBS0fPZ9xy_enmH5Qgi0iSdBmwAn1CBnNghEKdMjvxTMjLxqn2mSO4gvxIh8ahJZDMN1p8KMYO98dM2XfyNndltnK-sd_DizNR9BQu10w5WSTLeFfOh61SxGKeq4Dt3W5USQlx7dEG7dRiBDvjFM6wo2HVeSnGEVphOwx80t1MQdhRN-YOHCAahIqy7Z0-BkPIIjTeUtl_pST8oMi0IgJoo9x1oomY3JZp2OxWuNyOVWDGVsDavGHc6wRhwK5pJrDceCWxNdPEwExeYA84WOAFXE2D6I3m",
"size": 934
}
}
]
},
"sizeEstimate": 11716
}