views:

76

answers:

0

I'm following the example, I already have authorized my application (=obtained the access token) but trying to access the inbox results in this:

  21:14.12 > NDIB1 AUTHENTICATE XOAUTH
  21:14.17 < + 
  21:14.17 write literal size 480
  21:14.74 < NDIB1 NO [ALERT] Invalid credentials (Failure)
  21:14.74 NO response: [ALERT] Invalid credentials (Failure)

This is the code:

import xoauth
import oauth2 as oauth
import imaplib

consumer = oauth.Consumer('anonymous', 'anonymous')
access_token = oauth.Token(my_access_token, my_access_token_secret)
user = my_gmail_address
proto = "imap" # is it right???
xoauth_requestor_id = user # and this???
xoauth_string = xoauth.GenerateXOauthString(consumer, access_token, user, proto, xoauth_requestor_id, '', '')
conn = imaplib.IMAP4_SSL('imap.googlemail.com')
conn.debug = 4
conn.authenticate('XOAUTH', lambda x: xoauth_string)
conn.select('INBOX')
print conn.list()

It fails on the conn.authenticate() call. Any idea?