I just started up with APIs and figured I'd play around with Gmail's. I'm looking to scrape all emails sent to me in the past month for some text analysis. I might just be being thick here or have missed some documentation somewhere (probably), but I can't figure out how to get the body of emails that had attachments. I'm not interested in the attachment, just the body of the email.
results = gmail.users().messages().list(labelIds=['INBOX'], q='to:me after: '+str(date),userId='me').execute()
mssg_list = results['messages']
for mssg in mssg_list:
m_id = mssg['id']
message = gmail.users().messages().get(userId='me', id=m_id).execute()
body = message['payload']['parts'][1]['body']
final_body = base64.urlsafe_b64decode(body['data'].decode("utf-8"))
For messages with attachments, it returns only attachmentId and size, rather than size and data. I tried reading the attachmentId to see if perhaps data was kept there instead, but no dice; it appears to just refer to the attachment. Where is the actual text body living?