我遵循示例,我已经授权了我的应用程序(=获得了访问令牌),但试图访问收件箱的结果如下:
21:14.12> NDIB1 AUTHENTICATE XOAUTH 21:14.17< + 21:14.17写文字大小480 21:14.74< NDIB1 NO [ALERT]无效凭证(失败) 21:14.74无回应:[ALERT]凭证无效(失败)这是代码:
导入xoauth 将oauth2导入为oauth 进口imaplib =消费oauth.Consumer( '匿名', '匿名') =的access_token oauth.Token(my_access_token,my_access_token_secret)用户= my_gmail_address 原=imap#是吗? xoauth_requestor_id =用户#和这个? xoauth_string = xoauth.GenerateXOauthString(consumer,access_token,user,proto,xoauth_requestor_id,'','') conn = imaplib.IMAP4_SSL('imap.googlemail') conn。调试= 4 conn.authenticate( 'XOAUTH',拉姆达X:xoauth_string) conn.select( '收件箱')打印conn.list()它在conn.authenticate()调用时失败。任何想法?上面的例子使用匿名进行身份验证,但是,您必须设置消费者密钥和消费者密钥到您已在管理域名控制面板中设置的值:
consumer = oauth.Consumer(< OAuth-Consumer-Key> ;,< OAuth-Consumer-Secret>)
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') 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?
解决方案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:
accounts.google/ManageDomains
Example:
consumer = oauth.Consumer(<OAuth-Consumer-Key>, <OAuth-Consumer-Secret>)
更多推荐
使用XOAUTH访问Gmail收件箱
发布评论