oauth2和imap与Gmail的连接 [英] oauth2 and imap connection with Gmail

查看:248
本文介绍了oauth2和imap与Gmail的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用oauth2和imap与Gmail连接,并且可以从 https:/中看到代码/github.com/simplegeo/python-oauth2 :

I need to use oauth2 and imap to connect with Gmail, and I can see the code from https://github.com/simplegeo/python-oauth2:

import oauth2 as oauth
import oauth2.clients.imap as imaplib

# Set up your Consumer and Token as per usual. Just like any other
# three-legged OAuth request.
consumer = oauth.Consumer('your_consumer_key', 'your_consumer_secret')
token = oauth.Token('your_users_3_legged_token', 'your_users_3_legged_token_secret')

# Setup the URL according to Google's XOAUTH implementation. Be sure
# to replace the email here with the appropriate email address that
# you wish to access.
url = "https://mail.google.com/mail/b/your_users_email@gmail.com/imap/"

conn = imaplib.IMAP4_SSL('imap.googlemail.com')
conn.debug = 4 

# This is the only thing in the API for impaplib.IMAP4_SSL that has 
# changed. You now authenticate with the URL, consumer, and token.
conn.authenticate(url, consumer, token)

# Once authenticated everything from the impalib.IMAP4_SSL class will 
# work as per usual without any modification to your code.
conn.select('INBOX')
print conn.list()

但是我不能在这里理解ConsumerToken.

But I cannot understand the Consumer and Token here.

  1. 它们是什么意思?
  2. 我如何分别获取它们的密钥和秘密?
  3. 我从 https://code获得的client_id和client_secret .google.com/p/google-mail-oauth2-tools/wiki/OAuth2DotPyRunThrough .这是Consumer还是Token?
  1. What do they mean?
  2. How can I get key and secret for them respectively?
  3. The client_id and client_secret I got from https://code.google.com/p/google-mail-oauth2-tools/wiki/OAuth2DotPyRunThrough. Is this Consumer or Token?

推荐答案

上面的代码示例适用于OAuth 1,而不适用于OAuth2.使用方密钥和密钥,令牌和令牌密钥都是OAuth 1术语.

The above code sample is for OAuth 1, not OAuth 2. Consumer key and secret, token and token secret are all OAuth 1 terms.

我认为混淆是由以下事实造成的:所使用的Python库称为"oauth2".以我的理解,这是OAuth 1库的第二个版本,名称很不幸.

I think the confusion is created by the fact that the Python library used is called "oauth2". In my understanding this is the second incarnation of an OAuth 1 library, the name is unfortunate.

将OAuth 2与Gmail结合使用的文档位于: https://developers.google.com/gmail/oauth_overview

The documentation for using OAuth 2 with Gmail is at: https://developers.google.com/gmail/oauth_overview

这篇关于oauth2和imap与Gmail的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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