使用XOAUTH访问Gmail收件箱

编程入门 行业动态 更新时间:2024-10-20 07:50:30
本文介绍了使用XOAUTH访问Gmail收件箱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我遵循示例,我已经授权了我的应用程序(=获得了访问令牌),但试图访问收件箱的结果如下:

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收件箱

本文发布于:2023-10-12 23:44:13,感谢您对本站的认可!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:收件箱   XOAUTH   Gmail

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!