简体   繁体   English

使用XOAUTH通过IMAP访问Gmail收件箱

[英]IMAP access to Gmail inbox with XOAUTH

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. 它在conn.authenticate()调用时失败。 Any idea? 任何想法?

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 https://accounts.google.com/ManageDomains

Example: 例:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM