I am writing a script which get the messages from an email inbox, checks the messages' subject, conditionally prints a.pdf attachment and then marks the message as read
.
I can read the messages, print the.pdf file conditaionall but can't mark the message as read
.
I am trying to use the following function in order to mark as read
:
def markEmailAsRead(service, message):
service.users().messages().modify()(userId='me', id=message['id'], body={'removeLabelIds': ['UNREAD']}).execute()
Which is the same as in every website I looked on but I am getting the following error:
Traceback (most recent call last):
File "path/main.py", line 110, in <module>
main()
File "path/main.py", line 64, in main
mapHeaders(service=service, message=m)
File "path/main.py", line 78, in mapHeaders
markEmailAsRead(service=service, message=message)
File "path/main.py", line 107, in markEmailAsRead
service.users().messages().modify()(userId='me', id=message['id'], body={'removeLabelIds': ['UNREAD']}).execute()
File "path\discovery.py", line 972, in method
raise TypeError('Missing required parameter "%s"' % name)
TypeError: Missing required parameter "userId"
Process finished with exit code 1
I also followed the last answer here - How to mark messages as read using gmail api as i parse? but I am still getting the same error...
I've not worked with the Gmail API in the past however I believe that you have made a simple mistake here:
File "path/main.py", line 107, in markEmailAsRead
service.users().messages().modify()(userId='me', id=message['id'], body={'removeLabelIds': ['UNREAD']}).execute()
You've tried to pass the correct arguments, but you've done so outside of the brackets that relate to the modify method and accidentally added an extra set of parentheses.
The modified code is:
service.users().messages().modify(userId='me', id=message['id'], body={'removeLabelIds': ['UNREAD']}).execute()
I may be wrong, however this is what I could figure out from some quick reading.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.