API General Understanding in regards to Python Gmail-api

190 views Asked by At

I just got started programming a year ago (on and off) and I am trying to save an attachment to a folder offline from my personal GMAIL account.

I was advised to use :

https://developers.google.com/gmail/api/quickstart/python I set up the

I authenticated the my account and now am trying to get comfortable with this tool.

There are some initial questions that I have

What is User ID ? is this my email ( [email protected])
or someone else's email ([email protected])

How do I get a email ID's ?

These questions stem from ...

 GET https://www.googleapis.com/gmail/v1/users/userId/messages/messageId/attachments/id

from the page :

https://developers.google.com/gmail/api/v1/reference/users/messages/attachments/get

Again I am just learning from a beginner place..

Thanks

1

There are 1 answers

0
Eric D On

Just use "me" as the userId as it says in the doc.

To get a messageId first you have to search (list) messages, using something like:

resp = gmail.users().messages().list(userId="me", q="has:attachment subject:'foo bar' before:"2014-01-05").execute()

you can then iterate through the 'messages' in that resp and

gmail.users().messages().get(userId="me", id=message['id']).execute()

The Gmail API guides are quite helpful, take a look at them, for example: https://developers.google.com/gmail/api/guides/filtering