My code should take a message in my inbox, check it for a link and then pull the link from the email and then trash it.
message = gmail_service.users().messages().get(userId='me', id=thread['id'], format='raw').execute() #get message using thread id
msg_str = base64.urlsafe_b64decode(message['raw'].encode('ASCII'))
msg = email.message_from_string(msg_str)
for part in msg.walk():
msg.get_payload()
if part.get_content_type() == 'text/html':
mytext = base64.urlsafe_b64decode(part.get_payload().encode('UTF-8'))
html = BeautifulSoup(mytext)
for link in html.find_all('a'):
mylink = link.get('href')
print mylink
try:
service.users().messages().trash(userId='me', id=thread['id']).execute()
print 'Message with id: %s trashed successfully.' % msg_id
except errors.HttpError, error:
print 'Could not trash ' + thread['id'] + ': %s' % error
The scope I have defined in my code is .modify
which should give me the permissions I need to trash a message without fail. Why am I getting the error:
<HttpError 403 when requesting https://www.googleapis.com/gmail/v1/users/me/messages/147d8c9a6348e437/trash?alt=json returned "Insufficient Permission">
Edit: Even the documented example returns a 403 forbidden error, this must be a bug with the Gmail API itself.