我需要使用 oauth2 和 imap 来连接 Gmail,我可以从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()
但我无法理解Consumer
and Token
。
- 他们的意思是什么?
- 我怎样才能分别为他们获取密钥和秘密?
- 我从https://code.google.com/p/google-mail-oauth2-tools/wiki/OAuth2DotPyRunThrough获得的 client_id 和 client_secret 。这是
Consumer
还是Token
?