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.http.*
import com.google.api.client.util.*
// 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)
// ドキュメントのアップロード
request = transport.buildPostRequest()
request.url = "https://docs.google.com/feeds/default/private/full"
fn = "test1.xls"
gh = new GoogleHeaders()
gh.setSlug(request.headers, fn)
content = new InputStreamContent()
content.fileInput = new File(fn)
content.type = "application/vnd.ms-excel"
request.content = content
request.execute().parseAsString()
動作環境
groovy 1.7.2, JDK6 Update20, gdata-java-2.2.1-alpha
関連情報
gdata-java-client
http://code.google.com/p/gdata-java-client/
0 件のコメント:
コメントを投稿