我正在尝试使用gmail_xauth(ruby gem)来查看用户的邮件.我首先使用谷歌注册我的应用程序,然后设置设计请求访问邮件:
config.omniauth :google, 'key', 'secret', :scope => 'https://mail.google.com/mail/feed/atom/'
Run Code Online (Sandbox Code Playgroud)
然后我浏览了outh/openid流程,谷歌提示我批准访问gmail,将我重新定向到带有令牌的应用程序和全知凭证中的秘密,我的Google帐户将我的应用程序列为授权访问我的数据.到现在为止还挺好.
现在,当我获取这些凭据并尝试将它们与gmail_xoauth一起使用时,如下所示:
require 'gmail_xoauth'
imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs =
nil, verify = false)
imap.authenticate('XOAUTH', '...@gmail.com',
:consumer_key => 'key,
:consumer_secret => 'secret',
:token => 'omniauth_returned_token',
:token_secret => 'omniauth_returned_secret'
)
Run Code Online (Sandbox Code Playgroud)
我收到错误"Net :: IMAP :: NoResponseError:无效凭据(失败)".
有趣的是,遵循gmail_xoauth README使用python脚本生成具有相同使用者的令牌,它确实有效.