I'm implementing a bot where I can read emails and I'm following the Gmail API. I can read all the labels and I have stored it in the list. I am not able to read the messages inside the label
credentials = get_credentials()
http = credentials.authorize(httplib2.Http())
service = discovery.build('gmail', 'v1', http=http)
results = service.users().labels().get('me',"INBOX").execute()
print (results.getName())
and I get an error -
results = service.users().labels().get('me',"INBOX").execute()
TypeError: method() takes exactly 1 argument (3 given)
The official api docs implementation get label is in java.
Can someone please tell me what I'm doing wrong?
SCOPES = 'https://www.googleapis.com/auth/gmail.readonly','https://mail.google.com/','https://www.googleapis.com/auth/gmail.modify','https://www.googleapis.com/auth/gmail.labels'
I think this is what you are supposed to do:
results = service.users().labels().list(userId='me').execute()
From the official documentation: https://developers.google.com/gmail/api/quickstart/python
Upon further reading, this seems to be a 2 stage process.
First you need to grab the list of messages with a query:
response = service.users().messages().list(userId=user_id, q=query,
pageToken=page_token).execute()
Then you grab the message by its ID:
message = service.users().messages().get(userId=user_id, id=msg_id).execute()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With