title: Gmail API - Parse message content (Base64 decoding?) with Javascript
body: <p>I'm trying to use the Gmail API to get a user's email, grab the message subject and body, and then display it on a webpage. I'll be doing other stuff with it, but this is the part that I am having difficulty with. I am using Angular.js.</p>
  
  <p>Here is my API call:</p>
  
  <pre><code>function makeApiCall() {
    gapi.client.load('gmail', 'v1', function() {
      var request = gapi.client.gmail.users.messages.list({
        labelIds: ['INBOX']
      });
      request.execute(function(resp) {
        var content = document.getElementById("message-list");
        angular.forEach(resp, function(message) {
          var email = gapi.client.gmail.users.messages.get({'id': message.id});
          // var raw = email.payload.parts;
          // console.log(raw);
          content.innerHTML += JSON.stringify(email) + "&lt;br&gt;";
        })
      });
    });
  }
  </code></pre>
  
  <p>So <code>gapi.client.gmail.users.messages.list</code> returns an array of my messages, with their ID numbers. That is working.</p>
  
  <p>The call to <code>gapi.client.gmail.users.messages.get({&lt;specific message ID&gt;})</code> outputs this - <code>{"B":{"method":"gmail.users.messages.get","rpcParams":{},"transport":{"name":"googleapis"}}}</code>.</p>
  
  <p>Not sure what that is, but trying to get the message payload (<code>email.payload.parts</code>), results in <code>undefined</code>. So, how can I get the message content?</p>
  
  <p>Also, I would assume that if I can get the message contents, I would then have to Base64 decode the contents to get some English out of it. Any suggestions for that would be of great help also. I've found this: <a href="https://github.com/kvz/phpjs">https://github.com/kvz/phpjs</a>, but since I'm not sure how to go about getting the message contents so that I can try and decode them, so not sure if that php.js is of an help in that regard.</p>