title: Download attachments from Gmail using Gmail API
body: <p>I am using <a href="https://developers.google.com/gmail/api" rel="nofollow noreferrer">Gmail API</a> to access my Gmail data and <a href="https://github.com/googleapis/google-api-python-client" rel="nofollow noreferrer">Google Python API client</a>.</p>
  <p>According to documentation to get the message <em>attachment</em> they gave one <a href="https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get" rel="nofollow noreferrer">sample</a> for Python. But the same code I tried then I am getting an error:</p>
  <blockquote>
  <p>AttributeError: 'Resource' object has no attribute 'user'</p>
  </blockquote>
  <p>The line where I am getting error:</p>
  
  <pre class="lang-python prettyprint-override"><code>message = service.user().messages().get(userId=user_id, id=msg_id).execute()
  </code></pre>
  <p>So I tried <code>users()</code> by replacing <code>user()</code>:</p>
  <pre class="lang-python prettyprint-override"><code>message = service.users().messages().get(userId=user_id, id=msg_id).execute()
  </code></pre>
  <p>But I am not getting <code>part['body']['data']</code> in <code>for part in message['payload']['parts']</code>.</p>