Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3,4,5...TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

MFC Examples

Web API Categories

ASN.1
Amazon EC2
Amazon Glacier
Amazon S3
Amazon S3 (new)
Amazon SES
Amazon SNS
Amazon SQS
Async
Azure Cloud Storage
Azure Service Bus
Azure Table Service
Base64
Bounced Email
Box
CAdES
CSR
CSV
Certificates
Compression
DKIM / DomainKey
DSA
Diffie-Hellman
Digital Signatures
Dropbox
Dynamics CRM
EBICS
ECC
Ed25519
Email Object
Encryption
FTP
FileAccess
Firebase
GMail REST API
GMail SMTP/IMAP/POP
Geolocation
Google APIs
Google Calendar
Google Cloud SQL
Google Cloud Storage
Google Drive
Google Photos
Google Sheets
Google Tasks
Gzip
HTML-to-XML/Text
HTTP

HTTP Misc
IMAP
JSON
JSON Web Encryption (JWE)
JSON Web Signatures (JWS)
JSON Web Token (JWT)
Java KeyStore (JKS)
MHT / HTML Email
MIME
MS Storage Providers
Microsoft Graph
NTLM
OAuth1
OAuth2
OIDC
Office365
OneDrive
OpenSSL
Outlook
Outlook Calendar
Outlook Contact
PDF Signatures
PEM
PFX/P12
PKCS11
POP3
PRNG
REST
REST Misc
RSA
SCP
SCard
SFTP
SMTP
SSH
SSH Key
SSH Tunnel
ScMinidriver
SharePoint
Socket/SSL/TLS
Spider
Stream
Tar Archive
Upload
WebSocket
XAdES
XML
XML Digital Signatures
XMP
Zip
curl

 

 

 

(MFC) Get GMail Message format=full

Examines the JSON returned when getting a message using format=full.

For more information, see https://developers.google.com/gmail/api/v1/reference/users/messages/get

Chilkat C/C++ Library Downloads

MS Visual C/C++ Libs

See Also: Using MFC CString in Chilkat

#include <CkHttp.h>
#include <CkHttpResponse.h>
#include <CkJsonObject.h>

void ChilkatSample(void)
    {
    CkString strOut;

    // This example requires the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    CkHttp http;

    http.put_AuthToken("ACCESS_TOKEN");

    http.put_Accept("application/json");

    // This is the ID for a particular message in our mailbox...
    const char *id = "1712bc1dc22da2a2";

    // Download the message using format=full
    http.SetUrlVar("id",id);

    CkHttpResponse *resp = http.QuickRequest("GET","https://www.googleapis.com/gmail/v1/users/userId/messages/{$id}?format=full");
    if (http.get_LastMethodSuccess() != true) {
        strOut.append(http.lastErrorText());
        strOut.append("\r\n");
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    strOut.append("Response Status Code: ");
    strOut.appendInt(resp->get_StatusCode());
    strOut.append("\r\n");

    CkJsonObject json;
    json.Load(resp->bodyStr());
    json.put_EmitCompact(false);
    strOut.append(json.emit());
    strOut.append("\r\n");

    if (resp->get_StatusCode() != 200) {
        strOut.append("Failed.");
        strOut.append("\r\n");
        delete resp;
        SetDlgItemText(IDC_EDIT1,strOut.getUnicode());
        return;
    }

    delete resp;

    // Use this online tool to generate parsing code from sample JSON: 
    // Generate Parsing Code from JSON

    // Here is a sample "format=full" response that contains 4 attachments:
    // The JSON parsing source code is shown below...

    // {
    //   "id": "1712bc1dc22da2a2",
    //   "threadId": "1712bc1dc22da2a2",
    //   "labelIds": [
    //     "UNREAD",
    //     "IMPORTANT",
    //     "CATEGORY_PERSONAL",
    //     "INBOX"
    //   ],
    //   "snippet": "Hello, this is a test email with attachments..",
    //   "historyId": "759379",
    //   "internalDate": "1585577056000",
    //   "payload": {
    //     "partId": "",
    //     "mimeType": "multipart/mixed",
    //     "filename": "",
    //     "headers": [
    //       {
    //         "name": "Delivered-To",
    //         "value": "chilkat.support@gmail.com"
    //       },
    //       {
    //         "name": "Received",
    //         "value": "..."
    //       },
    //       {
    //         "name": "X-Received",
    //         "value": "..."
    //       },
    //       {
    //         "name": "X-Google-Smtp-Source",
    //         "value": "..."
    //       },
    //       {
    //         "name": "X-Received",
    //         "value": "..."
    //       },
    //       {
    //         "name": "ARC-Seal",
    //         "value": "..."
    //       },
    //       {
    //         "name": "ARC-Message-Signature",
    //         "value": "..."
    //       },
    //       {
    //         "name": "ARC-Authentication-Results",
    //         "value": "..."
    //       },
    //       {
    //         "name": "Return-Path",
    //         "value": "..."
    //       },
    //       {
    //         "name": "Received",
    //         "value": "..."
    //       },
    //       {
    //         "name": "Received-SPF",
    //         "value": "..."
    //       },
    //       {
    //         "name": "Authentication-Results",
    //         "value": "..."
    //       },
    //       {
    //         "name": "DKIM-Signature",
    //         "value": "..."
    //       },
    //       {
    //         "name": "DKIM-Signature",
    //         "value": "..."
    //       },
    //       {
    //         "name": "Subject",
    //         "value": "Test email with attachments"
    //       },
    //       {
    //         "name": "From",
    //         "value": "..."
    //       },
    //       {
    //         "name": "To",
    //         "value": "..."
    //       },
    //       {
    //         "name": "Date",
    //         "value": "Mon, 30 Mar 2020 14:04:16 +0000"
    //       },
    //       {
    //         "name": "Mime-Version",
    //         "value": "1.0"
    //       },
    //       {
    //         "name": "Content-Type",
    //         "value": "multipart/mixed;  boundary=\"=_wNvwW3YTnQBZ24pmfFNfay3S6M-pHT7KdZIkXwYF-BFiPYNE\""
    //       },
    //       {
    //         "name": "References",
    //         "value": "..."
    //       },
    //       {
    //         "name": "X-Mailer",
    //         "value": "..."
    //       },
    //       {
    //         "name": "Thread-Index",
    //         "value": "AQHWBpwYB0UZvgGPT1KluJJUCF0BGg=="
    //       },
    //       {
    //         "name": "Thread-Topic",
    //         "value": "Test email with attachments"
    //       },
    //       {
    //         "name": "Message-ID",
    //         "value": "..."
    //       },
    //       {
    //         "name": "X-SES-Outgoing",
    //         "value": "2020.03.30-54.240.27.106"
    //       },
    //       {
    //         "name": "Feedback-ID",
    //         "value": "..."
    //       }
    //     ],
    //     "body": {
    //       "size": 0
    //     },
    //     "parts": [
    //       {
    //         "partId": "0",
    //         "mimeType": "multipart/alternative",
    //         "filename": "",
    //         "headers": [
    //           {
    //             "name": "Content-Type",
    //             "value": "multipart/alternative;  boundary=\"=_wNvwHW2hdOZkYPaJAhdOY4+XBEFNAcvIZ1sQcW4JkBcAdDqA\""
    //           }
    //         ],
    //         "body": {
    //           "size": 0
    //         },
    //         "parts": [
    //           {
    //             "partId": "0.0",
    //             "mimeType": "text/plain",
    //             "filename": "",
    //             "headers": [
    //               {
    //                 "name": "Content-Type",
    //                 "value": "text/plain; charset=UTF-8"
    //               },
    //               {
    //                 "name": "Content-Transfer-Encoding",
    //                 "value": "7bit"
    //               }
    //             ],
    //             "body": {
    //               "size": 129,
    //               "data": "SGVsbG8sIHRoaXMgaXMgYSB0ZXN0IGVtYWlsIHdpdGggYXR0YWNobWVudHMuLg0KIA0KIA0KIA0KLS0gDQogQmVzdCBSZWdhcmRzLA0KIE1hdHQgRmF1c2V5DQogQ2hpbGthdCBTb2Z0d2FyZSwgSW5jLiANCg0KIA0KDQogDQog"
    //             }
    //           },
    //           {
    //             "partId": "0.1",
    //             "mimeType": "multipart/related",
    //             "filename": "",
    //             "headers": [
    //               {
    //                 "name": "Content-Type",
    //                 "value": "multipart/related;  boundary=\"=_wNvw-LQZP2xD5vBm4q4esgoD5F4j3w+DRPUkkzOidpnpXAre\""
    //               }
    //             ],
    //             "body": {
    //               "size": 0
    //             },
    //             "parts": [
    //               {
    //                 "partId": "0.1.0",
    //                 "mimeType": "text/html",
    //                 "filename": "",
    //                 "headers": [
    //                   {
    //                     "name": "Content-Type",
    //                     "value": "text/html; charset=utf-8"
    //                   },
    //                   {
    //                     "name": "Content-Transfer-Encoding",
    //                     "value": "7bit"
    //                   }
    //                 ],
    //                 "body": {
    //                   "size": 530,
    //                   "data": "PGh0bWw-DQogIDxoZWFkPg0KDQogICAgPG1ldGEgaHR0cC1lcXVpdj0iY29udGVudC10eXBlIiBjb250ZW50PSJ0ZXh0L2h0bWw7IGNoYXJzZXQ9VVRGLTgiPg0KICA8L2hlYWQ-DQogIDxib2R5Pg0KICAgIEhlbGxvLCB0aGlzIGlzIGE8Zm9udCBjb2xvcj0iI2ZmMDAwMCI-IHRlc3Q8L2ZvbnQ-IGVtYWlsIHdpdGgNCiAgICBhdHRhY2htZW50cy4uPGJyPg0KICAgIDxicj4NCiAgICA8aW1nIG1vei1kby1ub3Qtc2VuZD0iZmFsc2UiDQogICAgICBzcmM9ImNpZDpwYXJ0MS5GMEI1MzVEQi5DQjZFN0ExMkBjaGlsa2F0c29mdC5jb20iIGFsdD0ic2VhaG9yc2UiDQogICAgICB3aWR0aD0iMTIwIiBoZWlnaHQ9IjEyMCI-PGJyPg0KICAgIDxkaXYgY2xhc3M9Im1vei1zaWduYXR1cmUiPi0tIDxicj4NCiAgICAgIEJlc3QgUmVnYXJkcyw8YnI-DQogICAgICBNYXR0IEZhdXNleTxicj4NCiAgICAgIENoaWxrYXQgU29mdHdhcmUsIEluYy4NCiAgICAgIDxwPg0KICAgICAgPC9wPg0KICAgIDwvZGl2Pg0KICA8L2JvZHk-DQo8L2h0bWw-DQo="
    //                 }
    //               },
    //               {
    //                 "partId": "0.1.1",
    //                 "mimeType": "image/jpeg",
    //                 "filename": "seahorse.jpg",
    //                 "headers": [
    //                   {
    //                     "name": "Content-Type",
    //                     "value": "image/jpeg"
    //                   },
    //                   {
    //                     "name": "Content-Id",
    //                     "value": "\u003cpart1.F0B535DB.CB6E7A12@chilkatsoft.com\u003e"
    //                   },
    //                   {
    //                     "name": "Content-Disposition",
    //                     "value": "inline; filename=seahorse.jpg"
    //                   },
    //                   {
    //                     "name": "Content-Transfer-Encoding",
    //                     "value": "base64"
    //                   }
    //                 ],
    //                 "body": {
    //                   "attachmentId": "ANGjdJ-Z1c9gUGsEzexYYEsF5nLHGUaNiZQs5HkuFQVPo5jq1eze8poigmarvERUIRj1coKUaftiQPWhiZWaFyLDcyjFbfLdjWyyO3AxRO8pY5liAhVp1bt_5f79Nk0vfnZXL0OnZmNAMdrcFe645DbsajwDZcoYnWVcsV9Fe6PCNq41e6XW8Ko4Ex7zMzkATiwlLyx0RLcR0hl-FuZ-UVpQI0JeMTkNi4eN5-9L4dRU7HTo9qEyFW_p3__vXrnEJvmEvWXNUqxKLktcZvkvql6mnAVMDiIapqsE6x0EAvFobre7sf1_T6ieVlA-m92vrtELC2HHdxzkU-qhC_LuoOSOz8nd8tfWsrB8zex0v6NFFP9mJmBUb1QGtCGTxLdI40z_LdMOSiaqmeCq4o_s",
    //                   "size": 24388
    //                 }
    //               }
    //             ]
    //           }
    //         ]
    //       },
    //       {
    //         "partId": "1",
    //         "mimeType": "application/pdf",
    //         "filename": "helloWorld.pdf",
    //         "headers": [
    //           {
    //             "name": "Content-Type",
    //             "value": "application/pdf; name=helloWorld.pdf"
    //           },
    //           {
    //             "name": "Content-Transfer-Encoding",
    //             "value": "base64"
    //           },
    //           {
    //             "name": "Content-Disposition",
    //             "value": "attachment; filename=helloWorld.pdf"
    //           }
    //         ],
    //         "body": {
    //           "attachmentId": "ANGjdJ-oy3aCuZISJKLAhUdaEksCEklbAPyMaWzFgqOMGbPCRkgwgeu_Kttd99C17OBTHROkDZGekibTKWXGfscB5ww7fw4E65_V1dQ-jHhb2TD1Cdm58-BbNw2iDxzptco8iILPiSnLLfFn5Ps7nsRcxHaGTt3r0yqFKCuIYNnPK1vM04BXI_cfzo-HnI4I3tD6oHNHOGVQrL01MdShFQjPELPUjXM8z1qs7Kom-QyvV1iOldUN-66UuhynsmDX-CMM5TIdB-8KD_lmdhf-0DqG8JnCA20XpXyfqwS8XFkPA-t-QSjb7SdkHQFtQ4lz2PcBREFzZ2eI5j0l0Y_dQHRPYTeMwkVl1yl4MfFT4C4iso3VSF-eqaIjiFCbXKCFNyeEIW5WFsv189dhlSqU",
    //           "size": 934
    //         }
    //       },
    //       {
    //         "partId": "2",
    //         "mimeType": "application/x-gzip",
    //         "filename": "hamlet.xml.gz",
    //         "headers": [
    //           {
    //             "name": "Content-Type",
    //             "value": "application/x-gzip; name=hamlet.xml.gz"
    //           },
    //           {
    //             "name": "Content-Transfer-Encoding",
    //             "value": "base64"
    //           },
    //           {
    //             "name": "Content-Disposition",
    //             "value": "attachment; filename=hamlet.xml.gz"
    //           }
    //         ],
    //         "body": {
    //           "attachmentId": "ANGjdJ9rvj1ebIc-f0cXG0kwsb6pDBkRCNk3IQXbJ5z0-s2mEcVat3Pp6pVm3rTkRLOyeXHzRcTuel7nxRFJX6WVAKtG-5B-GL_b6DlsOWOzH4A_IKlyJ9U4aeWT02CgQL8oRwlCu1h0BtnY6lT8zureboGOqR7qoa-i5jH8xr6ds0nUDZp71lAwfOjji3eG6Wg6HfzWzWUThYPH3ba0_q35Jii8JIMhyJwwZnGjN3lvW_VhN6UIL1DIpop95b8rdwJdpyUavm7VhGtdNrI-mpgWQtT7WIAdIe6a-O74Zf4AB7uG7bp9R-IMBqQT-1jQqkN2_xlSpe3meWbuNu-4zsYfXN-IqM-Iy4dudAXjt0aY3Y8zxuHfW5qT7o4u8wSszhTIjM1j8lt-N7GZqnwJ",
    //           "size": 77409
    //         }
    //       },
    //       {
    //         "partId": "3",
    //         "mimeType": "text/plain",
    //         "filename": "brasil_cert.pem",
    //         "headers": [
    //           {
    //             "name": "Content-Type",
    //             "value": "text/plain; name=brasil_cert.pem"
    //           },
    //           {
    //             "name": "Content-Transfer-Encoding",
    //             "value": "base64"
    //           },
    //           {
    //             "name": "Content-Disposition",
    //             "value": "attachment; filename=brasil_cert.pem"
    //           }
    //         ],
    //         "body": {
    //           "attachmentId": "ANGjdJ8nGD_xRHvjDwNIaSUleWCWk15ksUleks0fJ29gfGVOebzjBOUnAHYgKPefUQ6d6ExtqYubpvGCka1kJAB4gFwsnhQeflBhFNkORBqtb6FAGq0FcNgrbuxyKywmoHOUV4GDsNs4OGroEcFhBeZNQ8XKEdEoaO8ht8DARn2LncjxioQ4TmZ6jawmMF-mLbW1mz4QjwNir5jLOsE11tYZV2tLDoqjsubKeJJA8xojWo9r50zWfJFgWJKXZJwyNvKyZTwLmmBL_ATFxLFp4Nvo4K37uuVdUCG8WXiWwNr0oIV1RZOd_ZOA7M6Jif0wUcppJdxXRqlsFJqGlcVsLowkVGrJNAMe-fLY1x4w5od3axZIdZQgBPlVRKYYu5xopPTrLJsn4ld7pNyAhpZW",
    //           "size": 2952
    //         }
    //       },
    //       {
    //         "partId": "4",
    //         "mimeType": "application/x-zip-compressed",
    //         "filename": "helloWorld.zip",
    //         "headers": [
    //           {
    //             "name": "Content-Type",
    //             "value": "application/x-zip-compressed; name=helloWorld.zip"
    //           },
    //           {
    //             "name": "Content-Transfer-Encoding",
    //             "value": "base64"
    //           },
    //           {
    //             "name": "Content-Disposition",
    //             "value": "attachment; filename=helloWorld.zip"
    //           }
    //         ],
    //         "body": {
    //           "attachmentId": "ANGjdJ9nWglkRNneBVGFk5GwSg83COa0zBeiTAvoMYniPklY03-w93dmEVHJTB9CAu5WMFW_yhV4ou2oX2w9SlpZjjyTgSc7sfYWeuX3pt29z67agy9WUVYeNGpo_30LSPgeyNk_Nm0DTAaektJTEMSy65rjRyK03VkHahNpMLY6Kd_pdfrk50oceuXzwNJZ-V-bftmIluueoQMqLcWQSGBRvEdIcl6EcPFFw8KuMLrjZZJwq8_bb8uM6zUvV23Q9LsLTgWg8FaBWejBf0wuIFXl3ZhtSLa-Y8OXCApHPdUnn45hccAzaQEmy4ZG7cgvCdN_jA9eFX46HYHty7ewleKPFGLTVof2JWsMiIi9BPqfohqQ5FPm1WXlGG_bOHvaMdoWcoqbKMMvF8lWZsfz",
    //           "size": 174
    //         }
    //       }
    //     ]
    //   },
    //   "sizeEstimate": 152847
    // }

    // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
    // See this example explaining how this memory should be used: const char * functions.

    const char *strVal = 0;
    const char *name = 0;
    const char *value = 0;
    const char *partId = 0;
    const char *mimeType = 0;
    const char *filename = 0;
    int bodySize;
    const char *bodyAttachmentId = 0;
    int j;
    int count_j;
    const char *bodyData = 0;
    int k;
    int count_k;
    CkJsonObject *json1 = 0;
    int i1;
    int count_i1;

    const char *id = json.stringOf("id");
    const char *threadId = json.stringOf("threadId");
    const char *snippet = json.stringOf("snippet");
    const char *historyId = json.stringOf("historyId");
    const char *internalDate = json.stringOf("internalDate");
    const char *payloadPartId = json.stringOf("payload.partId");
    const char *payloadMimeType = json.stringOf("payload.mimeType");
    const char *payloadFilename = json.stringOf("payload.filename");
    int payloadBodySize = json.IntOf("payload.body.size");
    int sizeEstimate = json.IntOf("sizeEstimate");
    int i = 0;
    int count_i = json.SizeOfArray("labelIds");
    while (i < count_i) {
        json.put_I(i);
        strVal = json.stringOf("labelIds[i]");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("payload.headers");
    while (i < count_i) {
        json.put_I(i);
        name = json.stringOf("payload.headers[i].name");
        value = json.stringOf("payload.headers[i].value");
        i = i + 1;
    }

    i = 0;
    count_i = json.SizeOfArray("payload.parts");
    while (i < count_i) {
        json.put_I(i);
        partId = json.stringOf("payload.parts[i].partId");
        mimeType = json.stringOf("payload.parts[i].mimeType");
        filename = json.stringOf("payload.parts[i].filename");
        bodySize = json.IntOf("payload.parts[i].body.size");
        bodyAttachmentId = json.stringOf("payload.parts[i].body.attachmentId");
        j = 0;
        count_j = json.SizeOfArray("payload.parts[i].headers");
        while (j < count_j) {
            json.put_J(j);
            name = json.stringOf("payload.parts[i].headers[j].name");
            value = json.stringOf("payload.parts[i].headers[j].value");
            j = j + 1;
        }

        j = 0;
        count_j = json.SizeOfArray("payload.parts[i].parts");
        while (j < count_j) {
            json.put_J(j);
            partId = json.stringOf("payload.parts[i].parts[j].partId");
            mimeType = json.stringOf("payload.parts[i].parts[j].mimeType");
            filename = json.stringOf("payload.parts[i].parts[j].filename");
            bodySize = json.IntOf("payload.parts[i].parts[j].body.size");
            bodyData = json.stringOf("payload.parts[i].parts[j].body.data");
            k = 0;
            count_k = json.SizeOfArray("payload.parts[i].parts[j].headers");
            while (k < count_k) {
                json.put_K(k);
                name = json.stringOf("payload.parts[i].parts[j].headers[k].name");
                value = json.stringOf("payload.parts[i].parts[j].headers[k].value");
                k = k + 1;
            }

            k = 0;
            count_k = json.SizeOfArray("payload.parts[i].parts[j].parts");
            while (k < count_k) {
                json.put_K(k);
                partId = json.stringOf("payload.parts[i].parts[j].parts[k].partId");
                mimeType = json.stringOf("payload.parts[i].parts[j].parts[k].mimeType");
                filename = json.stringOf("payload.parts[i].parts[j].parts[k].filename");
                bodySize = json.IntOf("payload.parts[i].parts[j].parts[k].body.size");
                bodyData = json.stringOf("payload.parts[i].parts[j].parts[k].body.data");
                bodyAttachmentId = json.stringOf("payload.parts[i].parts[j].parts[k].body.attachmentId");

                json1 = json.ObjectOf("payload.parts[i].parts[j].parts[k]");
                i1 = 0;
                count_i1 = json1->SizeOfArray("headers");
                while (i1 < count_i1) {
                    json1->put_I(i1);
                    name = json1->stringOf("headers[i].name");
                    value = json1->stringOf("headers[i].value");
                    i1 = i1 + 1;
                }

                delete json1;
                k = k + 1;
            }

            j = j + 1;
        }

        i = i + 1;
    }



    SetDlgItemText(IDC_EDIT1,strOut.getUnicode());

    }

 

© 2000-2022 Chilkat Software, Inc. All Rights Reserved.