【问题标题】:IMAP access to Gmail inbox with XOAUTH使用 XOAUTH 对 Gmail 收件箱的 IMAP 访问
【发布时间】:2011-04-14 22:07:40
【问题描述】:

我正在关注example,我已经授权我的应用程序(=获得访问令牌)但尝试访问收件箱会导致:

  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() 调用失败。有什么想法吗?

【问题讨论】:

  • 你解决过这个问题吗?我也有同样的问题。
  • 需要指定端口吗? (993)

标签: python oauth gmail imap


【解决方案1】:

上面的示例使用“匿名”进行身份验证,但您必须将“消费者密钥”和“消费者秘密”设置为您已在“管理域”控制面板中设置的值:

https://accounts.google.com/ManageDomains

例子:

consumer = oauth.Consumer(<OAuth-Consumer-Key>, <OAuth-Consumer-Secret>)

【讨论】:

  • 只有在您拥有自己的域时才适用。 “匿名”密钥/密钥与 Google 的 3-legged OAuth 示例代码一致。
猜你喜欢
  • 2011-04-03
  • 2011-05-30
  • 2011-07-10
  • 1970-01-01
  • 2013-04-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-26
相关资源
最近更新 更多