title: Retrieve single/multiple attachments Gmail API PHP
body: <p>I'm trying to get a list of all the attachments in my mailbox using Gmail API PHP. I'm getting stuck at some point but I can't really figure where. Here's the code I'm using to get the message content, when I try to get the attachments it somehow fails.</p>
  
  <p>I would like to get the filename and Attachment ID for all the messages corresponding to my "q" query. Here's my code:</p>
  
  <pre><code>
      function atta($service, $userId, $expeditor)
            {
              try
              {
                unset($optParamsamz);
                $optParamsamz = [];
                $optParamsamz['maxResults'] = 10; // Return Only 5 Messages
                $optParamsamz['q'] = "has:attachment larger_than:10000000 "; // Only show messages in Inbox
                $messagesamz = $service-&gt;users_messages-&gt;listUsersMessages('me',$optParamsamz);
                $listamz = $messagesamz-&gt;getMessages();
                $idlist = array();
                foreach ($listamz as $key =&gt; $value) {
                  $message = $service-&gt;users_messages-&gt;get('me', $value['id']);
                  $array_message = $message-&gt;getPayload();
                  print_r($array_message);
                  echo "&lt;br&gt;&lt;br&gt;";
                }
  
              }
              catch (Exception $e)
              {
                print 'An error occurred: ' . $e-&gt;getMessage();
              }
  
            }
  
  
  </code></pre>