Google Calendar data API
大方の予想通り、Atom Publishing ProtocolでGoogle Calendar Dataを操作できるようになった。もうどんなデータだろうが、日付情報さえあればGoogle Calendarに突っ込むことが可能だ。「Plaggerで何とか」の夢が広がりんぐ。
Google Code Blog: Google Calendar data API: time to starting coding!
Google Calendar Data API
弄っている時間がないのがとても残念。とりあえずこんな感じでPostでけた。
#!/usr/bin/perl
use strict;
use warnings;
use LWP::UserAgent;
use Encode;
use constant GAUTH_URL => 'https://www.google.com/accounts/ClientLogin';
use constant GCAL_URL => 'http://www.google.com/calendar/feeds/default/private/full';
my $email = 'user@gmail.com';
my $passwd = 'passwd';
my $entry = <<'ENTRY';
<entry xmlns='http://www.w3.org/2005/Atom'
xmlns:gd='http://schemas.google.com/g/2005'>
<category scheme='http://schemas.google.com/g/2005#kind'
term='http://schemas.google.com/g/2005#event'></category>
<title type='text'>Tennis with Beth</title>
<content type='text'>Meet for a quick lesson.</content>
<author>
<name>Jo March</name>
<email>jo@gmail.com</email>
</author>
<gd:transparency
value='http://schemas.google.com/g/2005#event.opaque'>
</gd:transparency>
<gd:eventStatus
value='http://schemas.google.com/g/2005#event.confirmed'>
</gd:eventStatus>
<gd:where valueString='Rolling Lawn Courts'></gd:where>
<gd:when startTime='2006-04-17T15:00:00.000Z'
endTime='2006-04-17T17:00:00.000Z'></gd:when>
</entry>
ENTRY
Encode::_utf8_off($entry);
my $ua = LWP::UserAgent->new();
my $auth = $ua->post(GAUTH_URL, {
Email => $email, Passwd => $passwd, source => 'test', service => 'cl'
});
my($auth_token) = $auth->content =~ m/Auth=(.+)/;
my $req = HTTP::Request->new(POST => GCAL_URL);
$req->header('Authorization', 'GoogleLogin auth=' . $auth_token);
$req->content_type('application/atom+xml');
$req->content_length(length $entry);
$req->content($entry);
my $res = $ua->request($req);
print $res->status_line . "\n";
if ($res->is_redirect && $res->header('Location')) {
$req->uri($res->header('Location'));
print $ua->request($req)->status_line . "\n";
}
Google Account AuthenticationをXML::Atom::Clientでtransparentに使えるともう少し楽になるだろう。
Cybozu Office 6のカレンダーの情報を同期するだけだったら、安直には全消去、全ストアをすれば十分かな。
それとは関係ないけど、いまだにPlaggerユーザではなく、bloglines2emailを愛用している私としては、livedoor Reader用にWebService::LivedoorReaderもでっち上げたいのだが…。
→コメント欄参照のこと。
Google Groups: Google Calendar Data APIで質問して分かったこと。
上記スクリプトにあるように http://www.google.com/calendar/feeds/default/private/full というEndpoint URLを使うと、アカウントユーザのプライマリカレンダー(My Calendarsの一番上のカレンダー)に追加される。このEndpoint URL自体は、以下のURLと等価である。
http://www.google.com/calendar/feeds/XXX@gmail.com/private/full
プライマリ以外のカレンダーに追加したい場合には、Web UI経由でそのカレンダーのPrivate AddressのFeed URLを調べる。と、以下のような感じになっているはず。
http://www.google.com/calendar/feeds/XXX@group.calendar.google.com/private-magic/basic
XXX@group.calendar.google.comの部分はカレンダーIDだろう(プライマリカレンダーの場合はアカウント名がカレンダーIDとして使用されていると考えると辻褄が合う)。で、Endpoint URLには、このURLからmagic部分を除去して以下のものを使用する。
http://www.google.com/calendar/feeds/XXX@group.calendar.google.com/private/basic
Endpoint URLをUI経由でしか知ることができないのはかなりアレな感じ。そのうち改善されると思う。
Comments and Trackbacks