Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gmail API python implementation

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'
like image 976
GodSaveTheDucks Avatar asked Mar 07 '26 02:03

GodSaveTheDucks


1 Answers

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()
like image 188
Max Uppenkamp Avatar answered Mar 09 '26 15:03

Max Uppenkamp