ruby ã® googlereaderã©ã¤ãã©ãª ã§ Google Reader API ã使ã£ã¦ã¿ã
çµæ§ä¾¿å©ã
ã¤ã³ã¹ãã¼ã«
æåã¯googlereaderã©ã¤ãã©ãªãã¤ã³ã¹ãã¼ã«ã
$ sudo gem install googlereader
èªè¨¼
ããã ãã§OK. ããã¯googlreaderã©ã¤ãã©ãªãããªãã¦ä¸ç·ã«ã¤ã³ã¹ãã¼ã«ããgooglebaseã©ã¤ãã©ãªã®æ©è½ã§ããã
require 'rubygems' require 'google/reader' require 'pp' config = { :email => "example@gmail.com" , :password => "mypassword" } pp Google::Base.establish_connection(config[:email], config[:password])
çµæãããªæãã«ã
warning: peer certificate won't be verified in this SSL session #<Google::Base:0x2b5ed7901210 @email="[email protected]", @password="mypassword", @sid= "DQAAAHkAAADmvlp1cjxsJvuR_C4nHXxHCfPC7AC4pAGUkMkd-qIp7fkcHyQB8ILAdR_eS_MTd86ZQyu-1CjMAPchL0fNXFgWsqEl0hCZ_BHNh2fpbqdsAK4yLP2sNozQyih60lxxDI7GkyV_WEDED5j3mYAML8xmf9KCl1b8NpChVZNwqDSROw">
SSLã®è¦å
ã§ãwarningãã§ã¦ãã以ä¸ã追å ããã°ããã¿ããã
http://www.5dollarwhitebox.org/drupal/node/64
class Net::HTTP alias_method :old_initialize, :initialize def initialize(*args) old_initialize(*args) @ssl_context = OpenSSL::SSL::SSLContext.new @ssl_context.verify_mode = OpenSSL::SSL::VERIFY_NONE end end
Googleã¢ã«ã¦ã³ãã®sidã¨token
çµæ§éè¦ã
config = { :email => "example@gmail.com" , :password => "mypassword" }
cnn = Google::Base.establish_connection(config[:email], config[:password])
puts cnn.sid
#=> DQAAAHoAAAATvLdZ_QOcge_R5OOm4ZLL8oK86YluqOvfPkzPiY4KbwGJg3sNlvNlbvx8h3wFdQThQ1lFgo724_nHZGKyCqQsYEmXEUgrEFh4BH99vRmX3rV7Ab_kWPng5lWfZEy85583Jn7eBI5Qtz-KzUZ_xIDAYeYxhDc4UUscJyAd7d1sOA
puts Google::Reader::Base.get_token
#=> KLWHOyYBAAA.Jq5UlKPYuleY5CeK8SGq4w.t-Oo2RGpMbDRIRPwW5gh3A
æªèªä»¶æ°ãåå¾
reading-listã¨ãããã¤ãç·æªèªæ°ã«ãªãã£ã½ãã
p Google::Reader::Count.all[0].count #=> 15 Google::Reader::Count.all.each {|feed| puts "count:#{feed.count} google_id:#{feed.google_id}" } #=> count:15 google_id:user/09054545224190070545/state/com.google/reading-list #=> count:7 google_id:feed/http://blog.goo.ne.jp/newseko/rss2.xml #=> count:8 google_id:feed/http://ichita.blog.so-net.ne.jp/index.rdf
ãã¹ã¦ã®ã©ãã«ãåå¾
starred, shared, blogger-following, ã¨ããã®ãäºç´ã§ããã£ã½ããbroadcast ã¨ããã©ãã«ãåºã¦ããæ°ãããã
pp Google::Reader::Label.all.map {|label|label.name} #=> ["starred", "shared", "jimin", "minshu", "broadcast", "blogger-following"]
ã©ãã«ãæå®ãã¦åå¾
ãã£ã¨ãå±±æ¬ä¸å¤ªãæªèªã ã£ãããã¾ããããã
pp Google::Reader::Label.new("jimin") #=> #<Google::Reader::Label:0x2abd8d707810 @count=0, @name="jimin", @shared=true> Google::Reader::Label.new("jimin").entries.each {|feed| puts "#{feed.links[0].href} #{feed.title}" } #=> http://ichita.blog.so-net.ne.jp/2010-01-17 æ¿æ¨©å VSæ¤å¯ã¨ããç°æ§ #=> http://ichita.blog.so-net.ne.jp/2010-01-16-4 ï¼ï¼ã«ãã¦æãæ¿æ²»å®¶ #=> http://ichita.blog.so-net.ne.jp/2010-01-16-3 䏿½æ ¹å¼æå¾æ´ä¼ãï¼ï¼å¹´ã¶ãã®æ¨æ¶
æªèªãæ¢èªã«å¤æ´
ããã§å±±æ¬ä¸å¤ªã®ã¢ã¤ãã ã¯ãã¹ã¦æ¢èªã«ãªãã¾ãããè¯ãã£ãè¯ãã£ãã
token = Google::Reader::Base.get_token state = Google::Reader::State::READ unread = Google::Reader::Label.new("jimin").entries(:unread, :n => 10) while true break if unread.size == 0 unread.each {|feed| ret = Google::Base.post(url, :form_data => {:i => feed.id, :a => state, :T => token}) puts "#{ret}: #{feed.title} #{feed.links[0].href}" } unread = Google::Reader::Label.new("jimin").entries(:unread, :n => 10, :c => unread.continuation) end #=> OK: å»ºè¨æ¥çã®æ²é³´ http://ichita.blog.so-net.ne.jp/2010-01-16-2 #=> OK: å°æ²¢å¹¹äºé·ã失èãããï¼ï¼ï¼ http://ichita.blog.so-net.ne.jp/2010-01-16-1 #=> OK: å±±æ¬ä¸å¤ªãçµã¿ããã¨æãæ¿æ²»å®¶ http://ichita.blog.so-net.ne.jp/2010-01-16
è³¼èªãã¦ãããã£ã¼ããè§£é¤
Google::Base.post ãã¡ããã£ã¨å¤æ´ããã ãã§ããããã®EditAPIãåç
§ã
2010/01/30追å
config = { :email => "example@gmail.com" , :password => "mypassword" }
cnn = Google::Base.establish_connection(config[:email], config[:password])
Google::Reader::Base.establish_connection(config[:email], config[:password])
token = Google::Reader::Base.get_token
url = Google::Reader::SUBSCRIPTION_EDIT_URL
Google::Reader::Subscription.all.each {|feed|
id = feed.google_id
ret = Google::Base.post(url, :form_data => {:s => id, :ac => 'unsubscribe', :T => token})
puts [ret,id].join(":")
}
ãã£ã¼ããæ°ãã«ç»é²
2010/01/30追å
config = { :email => "example@gmail.com" , :password => "mypassword" }
cnn = Google::Base.establish_connection(config[:email], config[:password])
Google::Reader::Base.establish_connection(config[:email], config[:password])
token = Google::Reader::Base.get_token
url = Google::Reader::SUBSCRIPTION_EDIT_URL
%w(
http://blog.goo.ne.jp/newseko/rss2.xml
http://ichita.blog.so-net.ne.jp/index.rdf
http://katsuya.weblogs.jp/blog/atom.xml
).each {|feed|
id = "feed/#{feed}"
ret = Google::Base.post(url, :form_data => {:s => id, :ac => 'subscribe', :T => token})
puts [ret,id].join(":")
}