我正在关注example http://code.google.com/p/google-mail-xoauth-tools/source/browse/trunk/python/xoauth.py,我已经授权了我的应用程序(=获得了访问令牌),但尝试访问收件箱会导致以下结果:
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)
这是代码:
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()
它在 conn.authenticate() 调用上失败。任何想法?
上面的示例使用“匿名”进行身份验证,但是您必须将“消费者密钥”和“消费者秘密”设置为您已在“管理域”控制面板中设置的值:
https://accounts.google.com/ManageDomains https://accounts.google.com/ManageDomains
Example:
consumer = oauth.Consumer(<OAuth-Consumer-Key>, <OAuth-Consumer-Secret>)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)