That won't address your error, but I have a Wrkflow that uses the Gmail API to get emails, message ID etc. It's more work but you get better control over Gmail by being able to reply to thread etc. Sharing it in case it is useful to you.
https://account.wrk.com/designer/?wrkflow_id=51019&client_id=621