2009年4月4日土曜日

Google app engineとGoogle data apiの連携について

取り組み始めて4日目にしてやっとスタートラインに立てた。

ポイントはGAEのローカルテスト環境。

一度しか使用できないトークンを何度でも使用できるトークンに
アップグレードしたい場合、ローカルではそれでエラーを出してしまう。_それ自体がなぜ起きるのかはまだ分からない。_そのためファイルをアップロードする必要があるらしい。

# coding=UTF-8
from google.appengine.ext import webapp
from google.appengine.ext.webapp.util import run_wsgi_app

import gdata.service
import gdata.alt.appengine
import settings
import atom.url
import cgi

class Test(webapp.RequestHandler):
def get(self):
next_url = atom.url.Url("http", settings.HOST_NAME, path="/")

client = gdata.service.GDataService()
gdata.alt.appengine.run_on_appengine(client)

self.response.out.write("""
<html><body>
<a href="%s">Request token</a>
""" % client.GenerateAuthSubURL(next_url,
("http://docs.google.com/feeds/",),
secure=False,
session=True))

doc_entry = "http://docs.google.com/feeds/documents/private/full"
auth_token = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)
session_token = None
if auth_token:
session_token = client.upgrade_to_session_token(auth_token)
else:
self.response.out.write("No")

client.current_token = session_token


self.response.out.write("""
<a href="%s"> TEST </a><br><br>
""" %client.GenerateAuthSubURL(next_url,
(doc_entry,),
secure=False,
session=True))
if session_token:
self.Ges(client, doc_entry)

self.response.out.write("</body></html>")

def Ges(self,client,feed_url):
res = client.Get(feed_url, converter=str)
self.response.out.write(res)

application = webapp.WSGIApplication([("/.*", Test)],
debug=True)

def main():
run_wsgi_app(application)

if __name__ == "__main__":
main()

0 件のコメント:

コメントを投稿