Oauth 2.0 oauth2和imap与Gmail的连接

Oauth 2.0 oauth2和imap与Gmail的连接,oauth-2.0,imap,google-oauth,gmail-imap,imaplib,Oauth 2.0,Imap,Google Oauth,Gmail Imap,Imaplib,我需要使用oauth2和imap连接Gmail,我可以从以下位置看到代码: 但是我无法理解这里的消费者和代币 它们是什么意思 我如何分别为他们获取密钥和机密 我从你那里得到的客户id和客户机密。这是消费者还是代币 上面的代码示例适用于OAuth 1,而不是OAuth 2。使用者密钥和密码、令牌和令牌密码都是OAuth 1术语 我认为混淆是由于使用的Python库被称为“oauth2”这一事实造成的。据我所知,这是OAuth 1库的第二个化身,名称很不幸 将OAuth 2与Gmail一起使用的文档

我需要使用oauth2和imap连接Gmail,我可以从以下位置看到代码:

但是我无法理解这里的
消费者
代币

  • 它们是什么意思
  • 我如何分别为他们获取密钥和机密
  • 我从你那里得到的客户id和客户机密。这是
    消费者
    还是
    代币

  • 上面的代码示例适用于OAuth 1,而不是OAuth 2。使用者密钥和密码、令牌和令牌密码都是OAuth 1术语

    我认为混淆是由于使用的Python库被称为“oauth2”这一事实造成的。据我所知,这是OAuth 1库的第二个化身,名称很不幸

    将OAuth 2与Gmail一起使用的文档位于:

    谢谢你的回答。但是您知道如何使用OAuth2实现身份验证吗?任何代码或文档都非常感谢。我只是编辑了答案并提供了文档的链接。我仍然感到困惑。比如说,如果我想访问用户A的gmail,访问令牌是由A生成的,不是我,对吗?通常你不能访问其他用户的电子邮件。是的,要访问A的电子邮件,A必须批准补助金。除非您正在管理托管域,否则在这种情况下,您可以使用服务帐户。域管理器必须为您的应用程序授予模拟访问权限。
    服务帐户
    是什么意思?但是我认为,
    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()