title: GMail API - How to display full emails from inbox
body: <p>EDIT: fixed first error! Listing message ids now , still trying to work out how to display full emails from inbox, if anyone could help would appreciate it.</p>
  
  <p>So I'm trying to use the GMail API to call the emails in my inbox so i can use them in my own app. I have got all the access sorted and currently have a array being returned. The problem i encounter is trying to display the messages.</p>
  
  <p>My php looks as follows</p>
  
  <pre><code>&lt;?php
  ini_set('display_errors' , 'On');
  error_reporting(E_ALL);
  
  // Start Session 
  session_start();
  
  //Include API autoloader
  require_once __DIR__ . '/vendor/autoload.php';
  
  // Create Google Client
  $client = new Google_Client();
  $client-&gt;setClientId('ID in here');
  $client-&gt;setClientSecret('Secret here');
  $client-&gt;setRedirectUri('http://localhost:8888/gmail/');
  $client-&gt;addScope('https://mail.google.com/');
  
  //Create Google Service
  $service = new Google_Service_Gmail($client);
  
  if(isset($_REQUEST['logout'])){
      unset($_SESSION['access_token']);
  }
  
  // Check if there is an auth token 
  if(isset($_GET['code']))
  {
      $client-&gt;authenticate($_GET['code']);
      $_SESSION['access_token'] = $client-&gt;getAccessToken();
      $url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
      header('Location: ' . filter_var($url, FILTER_VALIDATE_URL));
  }
  
  // Check for access token in session 
  if(isset($_SESSION['access_token']))
  {
      $client-&gt;setAccessToken($_SESSION['access_token']);
  } else 
  {
      $loginUrl = $client-&gt;createAuthUrl();
      echo 'Click &lt;a href="' . $loginUrl . '"&gt;here&lt;/a&gt; to login';
  }
  
  // Check if we have an access token ready for API Call
  try
  {
      if(isset($_SESSION['access_token']) &amp;&amp; $client-&gt;getAccessToken())
      {
          //make API calls
          $messages = $service-&gt;users_messages-&gt;listUsersMessages('me',['maxResults'=&gt; 2, 'labelIds'=&gt; 'INBOX']);
  
          foreach ($messages as $message) 
          {
              print 'Message with ID: ' . $message-&gt;getId() . '&lt;br/&gt;';
          }
  
          return $messages;
      }
  }
  catch (Google_Auth_Exception $e)
  {
      echo 'Looks like you dont have an access token or its expired';
  }
  </code></pre>