title: get message from 'message id' in gmail api
body: <p>i am trying to get message list from gmail by using gmail api. after getting list of message id i am trying to get content of message by passing message id which i got in first step.but i could not succeeded in getting message from message id.<pre><code></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;html&gt;
    &lt;head&gt;
      &lt;script type="text/javascript"&gt;
        // Your Client ID can be retrieved from your project in the Google
        // Developer Console, https://console.developers.google.com
        var CLIENT_ID = 'myclientId';
  
        var SCOPES = ['https://mail.google.com/'];
  
        /**
         * Check if current user has authorized this application.
         */
        function checkAuth() {
          gapi.auth.authorize(
            {
              'client_id': CLIENT_ID,
              'scope': SCOPES.join(' '),
              'immediate': true
            }, handleAuthResult);
        }
  
        /**
         * Handle response from authorization server.
         *
         * @param {Object} authResult Authorization result.
         */
        function handleAuthResult(authResult) {
          var authorizeDiv = document.getElementById('authorize-div');
          if (authResult &amp;&amp; !authResult.error) {
            // Hide auth UI, then load client library.
            authorizeDiv.style.display = 'none';
            loadGmailApi();
          } else {
            // Show auth UI, allowing the user to initiate authorization by
            // clicking authorize button.
            authorizeDiv.style.display = 'inline';
          }
        }
  
        /**
         * Initiate auth flow in response to user clicking authorize button.
         *
         * @param {Event} event Button click event.
         */
        function handleAuthClick(event) {
          gapi.auth.authorize(
            {client_id: CLIENT_ID, scope: SCOPES, immediate: false},
            handleAuthResult);
          return false;
        }
  
        /**
         * Load Gmail API client library. List labels once client library
         * is loaded.
         */
        function loadGmailApi() {
          gapi.client.load('gmail', 'v1', function(){
              listMessages();
              getMessage();
          });
        }
  
        /**
         * Print all Labels in the authorized user's inbox. If no labels
         * are found an appropriate message is printed.
         */
  
  
          var msgIds = [];
          function listMessages() {
    
         var request = gapi.client.gmail.users.messages.list({
            'userId': 'me',
            'q': 'from:xxxxx@xxxx.com'
          });
              request.execute(function(resp){
                  var msg = resp.messages;
                  if(msg.length&gt;0){
                      for(i = 0; i &lt; msg.length; i++){
                          
                          var msgid = msg[i];
                          msgIds.push(msg[i].id);
                          appendPre(msgid.id);
                      }
                      
                  }
                  }); 
              }
       
   function getMessage() {
      
    var request = gapi.client.gmail.users.messages.get({
      'userId': 'me',
      'id': msgIds[1];
    });
    request.execute(function(resp){
    var msgSnippet = resp.messages;
        
        if(msgSnippet.length&gt;0){
            appendPre(msgSnippet.snippet);
        }
        else{
            appendPre('no message found');
        }
    
    });
  }
    
     
  
          
          
        /**
         * Append a pre element to the body containing the given message
         * as its text node.
         *
         * @param {string} message Text to be placed in pre element.
         */
        function appendPre(message) {
          var pre = document.getElementById('output');
          var textContent = document.createTextNode(message + '\n');
          pre.appendChild(textContent);
        }
  
      &lt;/script&gt;
      &lt;script src="https://apis.google.com/js/client.js?onload=checkAuth"&gt;
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;div id="authorize-div" style="display: none"&gt;
        &lt;span&gt;Authorize access to Gmail API&lt;/span&gt;
        &lt;!--Button for the user to click to initiate auth sequence --&gt;
        &lt;button id="authorize-button" onclick="handleAuthClick(event)"&gt;
          Authorize
        &lt;/button&gt;
      &lt;/div&gt;
      &lt;pre id="output"&gt;&lt;/pre&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p></code></pre></p>