parker
parker

Reputation: 193

Can't authorize to Gmail via XOauth2 using Gmail Gem

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 protected]', :token => TOKEN)
c.login

from the console, I see:

#<Gmail::Client0x7fb037e80988 ([email protected]) disconnected>

If I try:

c.login!

I get the error:

Gmail::Client::AuthorizationError: Couldn't login to given Gmail account: [email protected] (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.

Upvotes: 1

Views: 444

Answers (1)

parker
parker

Reputation: 193

This was a syntax error. The correct syntax is:

gmail = Gmail.connect(:xoauth2, '[email protected]', TOKEN)

Upvotes: 1

Related Questions