ピクチャ 10.png

まだ基礎だけですが。とりあえず使うのはGDataライブラリです。

$ sudo gem install gdataSuccessfully installed GData-0.0.4Installing ri documentation for GData-0.0.4…Installing RDoc documentation for GData-0.0.4…

スクリプトは以下のように。
/opt/local/lib/ruby/gems/1.8/gems/GData-0.0.4/lib/gdata/google_contact.rb

require 'gdata/base'
require 'builder'
module GData
class GoogleContact < GData::Base
def initialize
super 'cp', 'gdata-ruby', 'www.google.com'
end

 def list
request "/m8/feeds/contacts/#{@email}/base"
end

 def authenticate(email, password)
@email = email
super email, password
end
end

使い方は簡単で、

require ‘gdata/google_contact’
>> gc = GData::GoogleContact.new
=> #<GData::GoogleContact:0×157cd34 @url=”www.google.com”, @source=”gdata-ruby”, @service=”cp”>
>> gc.authenticate “example@gmail.com”, “[your password]”
=> {”Authorization”=>”GoogleLogin auth=…\n”, “Content-Type”=>”application/atom+xml”}
>> gc.list

でリストがXMLで返ってきます。本当はこれをさらに解析してvCard形式とかでもとれるようになっていると便利そう。実際に返ってくるデータは次のような感じ(整形しています)。
=> ”
<?xml version=’1.0′ encoding=’UTF-8′?>
<feed xmlns=’http://www.w3.org/2005/Atom’ xmlns:openSearch=’http://a9.com/-/spec/opensearchrss/1.0/’ xmlns:gContact=’http://schemas.google.com/contact/2008′ xmlns:gd=’http://schemas.google.com/g/2005′>
<id>example@gmail.com</id>
<updated>2008-03-10T05:05:34.160Z</updated>
<category scheme=’http://schemas.google.com/g/2005#kind’ term=’http://schemas.google.com/contact/2008#contact’/>
<title type=’text’>Atsushi Nakatsugawa’s Contacts</title>
<link rel=’alternate’ type=’text/html’ href=’http://www.google.com/’/>
<link rel=’http://schemas.google.com/g/2005#feed’ type=’application/atom+xml’ href=’http://www.google.com/m8/feeds/contacts/moongift%40gmail.com/base’/>
<link rel=’http://schemas.google.com/g/2005#post’ type=’application/atom+xml’ href=’http://www.google.com/m8/feeds/contacts/moongift%40gmail.com/base’/>
<link rel=’self’ type=’application/atom+xml’ href=’http://www.google.com/m8/feeds/contacts/moongift%40gmail.com/base?max-results=25′/>
<link rel=’next’ type=’application/atom+xml’ href=’http://www.google.com/m8/feeds/contacts/moongift%40gmail.com/base?start-index=26&max-results=25′/>
<author>
<name>Atsushi Nakatsugawa</name>
<email>example@gmail.com</email>
</author>
<generator version=’1.0′ uri=’http://www.google.com/m8/feeds’>Contacts</generator>
<openSearch:totalResults>376</openSearch:totalResults>
<openSearch:startIndex>1</openSearch:startIndex>
<openSearch:itemsPerPage>25</openSearch:itemsPerPage>
<entry>
<id>http://www.google.com/m8/feeds/contacts/moongift%40gmail.com/base/0</id>
<updated>2007-11-26T02:27:10.592Z</updated>
<category scheme=’http://schemas.google.com/g/2005#kind’ term=’http://schemas.google.com/contact/2008#contact’/>
<title type=’text’>Atsushi Nakatsugawa</title>
<link rel=’self’ type=’application/atom+xml’ href=’http://www.google.com/m8/feeds/contacts/moongift%40gmail.com/base/0′/>
<link rel=’edit’ type=’application/atom+xml’ href=’http://www.google.com/m8/feeds/contacts/moongift%40gmail.com/base/0/1196044030592000′/>
<gd:email rel=’http://schemas.google.com/g/2005#other’ address=’example@moongift.jp’ primary=’true’/>
</entry>

タイトルにユーザ名が入って、gd:emailのaddressにメールアドレスが入る形ですね。個別で取得する場合はidを利用するようです。その他、住所などのデータも入っている場合は取得できます。とは言え、http://schemas.google.com/g/2005が見られないので、項目の詳細は不明です。

が、メールアドレスのリストだけであればこれで取得できるので便利です。

Leave a Reply

MOONGIFTネットワーク。こちらもぜひご覧ください。
MOONGIFT

Warning: array_slice() [function.array-slice]: The first argument should be an array in /virtual/producing/public_html/producing-web.com/wp-content/themes/network.php on line 15
  • No items
Open Service
Rails 2.0
Resident on Net
iPhone最適化
リーンソフトウェア
MarketPedia
Producing Web
Cool Coding