import com.google.api.client.googleapis.*
import com.google.api.client.googleapis.auth.clientlogin.*
import com.google.api.data.docs.v3.*
import com.google.api.data.docs.v3.atom.*
import com.google.api.client.xml.atom.*
import com.google.api.client.util.*
// エントリ
public class Entry
{
@Key
String id
@Key
String title
}
// リンク
public class Link
{
@Key("@rel")
String rel
@Key("@type")
String type
@Key("@href")
String href
}
// フィード
public class Feed
{
@Key
String title
@Key
List<Link> link
@Key
List<Entry> entry
}
// フォルダカテゴリ
public class FolderCategory
{
@Key("@scheme")
String scheme = "http://schemas.google.com/g/2005#kind"
@Key("@term")
String term = "http://schemas.google.com/docs/2007#folder"
}
// エントリ
public class FolderEntry
{
@Key
FolderCategory category = new FolderCategory()
@Key
String title
}
// Parser設定
GoogleTransport transport = new GoogleTransport()
transport.applicationName = "yourcorp-yourapp-1.0"
transport.setVersionHeader(GoogleDocumentsList.VERSION)
ap = new AtomParser()
ap.namespaceDictionary = GoogleDocumentsListAtom.NAMESPACE_DICTIONARY
transport.addParser(ap)
username = "youraccount@gmail.com"
password = 'yourpassword'
// 認証
cl = new ClientLogin()
cl.authTokenType = GoogleDocumentsList.AUTH_TOKEN_TYPE
cl.username = username
cl.password = password
cl.authenticate().setAuthorizationHeader(transport)
// フォルダ検索リクエスト
query = "テストフォルダ"
requrl = "https://docs.google.com/feeds/default/private/full/-/folder?title-exact=true&title=${URLEncoder.encode(query, "UTF-8")}"
while(requrl != null){
request = transport.buildGetRequest()
request.url = requrl
feed = request.execute().parseAs(Feed.class)
for(item in feed.entry){
// サブフォルダの作成
entry = new FolderEntry()
entry.title = "サブフォルダの作成テスト"
request = transport.buildPostRequest()
request.url = "https://docs.google.com/feeds/default/private/full/" +
"${item.id.substring(item.id.indexOf("folder%3A"))}/contents"
content = new AtomContent()
content.entry = entry
content.namespaceDictionary = GoogleDocumentsListAtom.NAMESPACE_DICTIONARY
request.content = content;
request.execute().parseAsString()
}
// 100個以上のアイテムの場合
requrl = null
for(link in feed.link){
if( link.rel == "next" ){
requrl = link.href
}
}
}
動作環境
groovy 1.7.2, JDK6 Update20, gdata-java-2.2.1-alpha
関連情報
gdata-java-client
http://code.google.com/p/gdata-java-client/
0 件のコメント:
コメントを投稿