gpt4 book ai didi

python - 使用 OAuth 2.0 访问 token 访问 Gmail Imap

转载 作者:太空狗 更新时间:2023-10-29 18:05:01 30 4
gpt4 key购买 nike

我正在使用 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')

有关详细信息,请参阅 library code .

关于python - 使用 OAuth 2.0 访问 token 访问 Gmail Imap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9134491/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com