1

I am attempting to use XOauth2 nd the ruby Gmail gem to read email from Google accounts. While I can retrieve a valid token via Oauth, I get an error trying to connect with the token via the Gmail Gem.

I am using OmniAuth to retrieve and store a token, TOKEN. I have confirmed that it is not expired and can be used to connect via Google::APIClient.

When I attempt to connect as follows:

gmail = Gmail.connect(:xoauth2, 'email@gmail.com', :token => TOKEN)
c.login

from the console, I see:

#<Gmail::Client0x7fb037e80988 (email@gmail.com) disconnected>

If I try:

c.login!

I get the error:

Gmail::Client::AuthorizationError: Couldn't login to given Gmail account: email@gmail.com (Invalid credentials (Failure))

Reviewing the Gmail gem source code, it looks like this should work. I am unclear how to debug or what I'm missing.

parker
  • 193
  • 1
  • 12
  • 1
    Try writing 'me' instead of 'email@gmail.com'. Does that work? – Tholle Jul 12 '15 at 11:24
  • No, that does not work. – parker Jul 13 '15 at 16:52
  • Aah, shoot. Then I don't know. Hopefully someone can chime in. – Tholle Jul 13 '15 at 17:16
  • How are you sending the access token? Are you sending it as Base64-encoded string. check this link . I think for gmail_Xoauth2, you can send unencoded access token. check this link for sample code http://stackoverflow.com/questions/16945880/generating-sasl-xoauth2-client-response-for-gmail-imap-access-using-ruby?rq=1 – SGC Jul 14 '15 at 20:50

1 Answers1

1

This was a syntax error. The correct syntax is:

gmail = Gmail.connect(:xoauth2, 'email@gmail.com', TOKEN)
parker
  • 193
  • 1
  • 12