使用 XOAUTH IMAP 访问 Gmail 收件箱
我正在遵循示例,我已经授权了我的应用程序(=获取了访问令牌),但尝试访问收件箱会导致以下结果:
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() 调用上失败。有什么想法吗?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
上面的示例使用“匿名”进行身份验证,但您必须将“消费者密钥”和“消费者秘密”设置为您已在“管理域”控制面板中设置的值:
https://accounts.google.com/ManageDomains
示例:
The example above uses "anonymous" for authentication but, you must set "Consumer Key" and "Consumer Secret" to the values you've already set in "Manage Domains" control panel at:
https://accounts.google.com/ManageDomains
Example: