2012-07-11 66 views
0

我正在爲我的應用使用oauth身份驗證,並計劃使用Oauth2。 有人可以告訴Gmail是否支持通過Oauth2訪問令牌獲取收件箱。我發現可以通過Oauth1令牌執行此操作,但我發現Oauth1支持現在已被Google棄用。使用oauth2獲取gmail

回答

2

不,現在只是OAuth 1.0。

+4

OAuth 2支持現已推出:https://developers.google.com/google-apps/gmail/oauth_overview – 2012-09-13 08:19:34

1

這裏是一個工作,用他們的XOAUTH2協議從谷歌獲取電子郵件的紅寶石例如:

imap = Net::IMAP.new('imap.gmail.com', 993, usessl = true, certs = nil, verify = false) 
imap.authenticate('XOAUTH2', '[email protected]', 'oauth2_access_token_goes_here') 
imap.select('INBOX') 
imap.search(['ALL']).each do |message_id| 

    msg = imap.fetch(message_id,'RFC822')[0].attr['RFC822'] 
    mail = Mail.read_from_string msg 

    puts mail.subject 
    puts mail.text_part.body.to_s 
    puts mail.html_part.body.to_s 

end 

注:此示例使用ruby mail寶石和gmail_xoauth寶石,所以你將需要安裝此代碼樣品上班。

此外,本示例中未顯示檢索OAuth2訪問令牌。 Here's an example using the ruby OmniAuth gem.

相關問題