Using the google Calendar app password in Ruby

亡梦爱人 提交于 2019-12-25 01:40:36

问题


I would like to use the new Google App password for Google Calendar feature in a Ruby script but can't find a gem or example. In the past you could logon with your google email and password but that stopped working a long time ago, tighter security..

I have an older example which uses oAuth and tokens etc but would like to try this much simpler approach.

I do have a working script for Gmail like below but would like to use the same way for Calendar, I allready have an app password for Agenda/Windows app. Each service and client needs another password you have to ask in your Google account security settings.

An example of reading the events for the next week would be great.

Here the working example with a Gmail app password.

require 'net/imap'

PASSWORD = 'xxxx xxxx xxxx xxxx' # all lower case letters
imap = Net::IMAP.new("imap.googlemail.com", 993, true, nil, false)
imap.login('xxxxxxxx@gmail.com', PASSWORD) 
imap.select('INBOX')

imap.search(['UNSEEN']).each do |message_id|
  envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
  puts "#{envelope.from[0].name}: #{envelope.subject.clean}"
end

imap.logout() 
imap.disconnect() 

来源:https://stackoverflow.com/questions/55981592/using-the-google-calendar-app-password-in-ruby

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!