使用OAuth 2.0访问令牌访问Gmail Imap [英] Access Gmail Imap with OAuth 2.0 Access token

查看:181
本文介绍了使用OAuth 2.0访问令牌访问Gmail Imap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Google的Oauth 2.0获取用户的access_token,但我不知道如何将它与imaplib配合使用来访问收件箱。

以下是使用oauth 2.0的IMAP的代码

  email ='k@example.com'
access_token ='vF9dft4qmTc2Nvb3RlckBhdHRhdmlzdGEuY29tCg'
auth_string ='user =%s\1auth = Bearer%s\1\1'%(email,access_token)

imap_conn = imaplib.IMAP4_SSL( 'imap.gmail.com')
imap_conn.debug = 4
imap_conn.authenticate('XOAUTH2',lambda x:auth_string)
imap_conn.select('INBOX')

了解详情: http://google-mail-oauth2-tools.googlecode.com/svn/trunk/python/oauth2.py


I am using Google's Oauth 2.0 to get the user's access_token, but I dont know how to use it with imaplib to access inbox.

解决方案

below is the code for IMAP with oauth 2.0

email = 'k@example.com'
access_token = 'vF9dft4qmTc2Nvb3RlckBhdHRhdmlzdGEuY29tCg'
auth_string = 'user=%s\1auth=Bearer %s\1\1' % (email, access_token)

imap_conn = imaplib.IMAP4_SSL('imap.gmail.com')
imap_conn.debug = 4
imap_conn.authenticate('XOAUTH2', lambda x: auth_string)
imap_conn.select('INBOX')

for more details: http://google-mail-oauth2-tools.googlecode.com/svn/trunk/python/oauth2.py

这篇关于使用OAuth 2.0访问令牌访问Gmail Imap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆