krutmaster

Gmail Api message body (text)

Jul 20th, 2020
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.33 KB | None | 0 0
  1. def getText(service, userId, msg_id):
  2.     message = gmail_service.users().messages().get(userId='me', id=msg_id, format='full').execute()
  3.     text = message.get('payload').get('parts')[0].get('body').get('data')
  4.  
  5.     if text:
  6.         return base64.urlsafe_b64decode(text.encode('ASCII')).decode('utf-8')
  7.  
  8.     return message['snippet']
Add Comment
Please, Sign In to add comment