import com.google.api.client.googleapis.*
import com.google.api.client.googleapis.auth.clientlogin.*
import com.google.api.data.calendar.v2.*
import com.google.api.data.calendar.v2.atom.*
import com.google.api.client.xml.atom.*
import com.google.api.client.util.*
// 日時
public class When
{
@Key("@startTime")
DateTime startTime
@Key("@endTime")
DateTime endTime
}
// エントリ
public class Entry
{
@Key
String title
@Key
String content
@Key("gd:when")
When when
}
// フィード
public class Feed
{
@Key
String title
@Key
List<Entry> entry
}
// Parser設定
GoogleTransport transport = new GoogleTransport()
transport.applicationName = "yourcorp-yourapp-1.0"
transport.setVersionHeader(GoogleCalendar.VERSION)
ap = new AtomParser()
ap.namespaceDictionary = GoogleCalendarAtom.NAMESPACE_DICTIONARY
transport.addParser(ap)
username = "youraccount@gmail.com"
password = 'yourpassword'
// 認証
cl = new ClientLogin()
cl.authTokenType = GoogleCalendar.AUTH_TOKEN_TYPE
cl.username = username
cl.password = password
cl.authenticate().setAuthorizationHeader(transport)
// デフォルトカレンダーから指定時間内のイベントを取得
request = transport.buildGetRequest();
st = new DateTime(new GregorianCalendar(2010, 6-1, 3, 10, 0, 0).getTime(),
TimeZone.getTimeZone("GMT+9")).toStringRfc3339()
et = new DateTime(new GregorianCalendar(2010, 6-1, 3, 13, 0, 0).getTime(),
TimeZone.getTimeZone("GMT+9")).toStringRfc3339()
request.url =
"http://www.google.com/calendar/feeds/default/private/full" +
"?start-min=${URLEncoder.encode(st, "UTF-8")}" +
"&start-max=${URLEncoder.encode(et, "UTF-8")}"
feed = request.execute().parseAs( Feed.class)
println "feed title:" + feed.title
for(item in feed.entry){
println "title:" + item.title
println "content:" + item.content
if( item.when != null ){
println "開始日時:" + item.when?.startTime
println "終了日時:" + item.when?.endTime
}
}
動作環境
groovy 1.7.2, JDK6 Update20, gdata-java-2.2.1-alpha
関連情報
gdata-java-client
http://code.google.com/p/gdata-java-client/
0 件のコメント:
コメントを投稿