2009年11月 のアーカイブ

DAYS 13 Gdataとの連動

2009年11月5日 木曜日

[ GAE Google App Engine ][ Phthon ][ Google Bigtable ][ AuthSub API ]
GAEアプリケーションとGoogleデータサービスとの連動について考えてみた。
ドキュメント、写真、動画については、
GAEのアプリケーションと連動することでどれだけのメリットがあるだろうか?
いろいろ考えたが、それぞれのアプリ側(GAEでない側)で
「共有」の設定をしてしまえば、事足りるのではないかと考えるようになった。
GAEでの作りこみの時間、コストを考えると、
人間側でルールを決め運用する方がパフォーマンスがよさそうである。
最初に、連動することによるメリットが高いと考えていたカレンダーと地図も
同じように「無理やり連動させることないんじゃなか?」と考えるようになり、
少しやる気をなくしている。
ただ、これは、私が、Googleデータサービスを使いきれていないからかもしれない。
もっと新しいことができるのに、古い考え方でそれを見逃しているのかもしれない。
私がつくったアプリ↓
協調型意思決定支援システム「○ 賛否両論 ×(ベータ版)」

http://sanpiryoron.appspot.com/

協調型プロジェクトタスク管理ツール「キャッチ&リリース(ベータ版)」

http://ctchandrls.appspot.com/

GoogleデータサービスAuthSub API利用サンプルアプリ

DAYS 12 AuthSub API

2009年11月4日 水曜日

[ GAE Google App Engine ][ Phthon ][ Google Bigtable ][ AuthSub API ]
GoogleデータサービスAuthSub API利用サンプルアプリ
GAEから利用できるGoogleデータサービスを使ってみた。
本来であれば、アプリケーションに絡めて連動するような形にしたかったが、
連動のさせ方がよくわからず、とりあえず、 「 AuthSub API 」を使って
認証をし、各Googleデータサービスのデータ一覧をとってくるというアプリを作成した。
何度も繰り返すが、本来であれば、協調型プロジェクトタスク管理ツール「キャッチ&リリース(ベータ版)」

http://ctchandrls.appspot.com/の締切日をGoogleカレンダーに連動させたかったのだが、

どうにも動かせない。
できたのは、一覧をとってくることぐらいだったのだ。
Google Data サービスの使用」オンラインマニュアルを参考にしたが、
最終的には、自分のやり方になってしまったように思う。
もしかしたら、これが原因で、「書き込み・更新・削除」の処理ができないのかもしれない。
オンラインマニュアルでは、以下のAPIが提供されていると書かれているが、
Google Data Python モジュールのバージョンがあがっているらしく、
ダウンロードサイトでは他のAPIについても書かれている。
ただ、GAEで利用できるものとは違うのかもしれない。
* 認証
* Google Base
* カレンダー
* 連絡先
* ドキュメント
* Picasa ウェブ アルバム
* スプレッドシート
* YouTube
その中で、私の作ったサンプルアプリでは、
5つのサービスの一覧をとってこれるようにした。
*GoogoleDocs
*GoogleCalender
*Picasa Web アルバム
*YouTube
*GoogleSpreadSheets
利用する前に気をつける点
・いうまでもないが、各サービスの利用を開始していなければ、アクセスはできない。
・YouTubeのみ、「マイ動画」一覧ではなく、「再生回数の多い動画」一覧をとってきている。
なぜならば、「マイ動画」一覧のデータにアクセスするには、Developer Registrationが必要で、私は登録していないからである。
処理のプロセスとしては、2ステップある。
最初のページを表示する際に、
トークンをリクエストするリンクを作成する。
リンクをクリックすると
Googleアカウントの「アクセス要求」に移り、
「アクセスを許可」することで、トークンが手に入る。
次のページを表示する際に、
トークンをアップグレードし、データを取得し、
一覧を表示する。
main.pyの抜粋を以下に記す。

<pre>~~~~~~省略~~~~~~~
class MainHandler(webapp.RequestHandler):
layout_file ='layout.html'
view_dir = '../views/'
layout = {
'title':'Googleデータアクセス',
'body_title':'Googleデータアクセス',
'heder_title':'',
'heder_content':'',
'header':'header.html',
'footer':'footer.html',
}
def get(self):
user = users.get_current_user()
if user:
self.layout['link'] = ("ようこそ、%s! (<a href="\">ログアウト</a>)" %
(user.nickname(), users.create_logout_url(self.request.uri)))
else:
self.layout['link'] = ("<a href="\">ログイン</a>." %
users.create_login_url(self.request.uri))
client = gdata.service.GDataService()
gdata.alt.appengine.run_on_appengine(client)
#
docs_gdataScope = 'http://docs.google.com/feeds/'
authsub_docs = atom.url.Url('http', settings.HOST_NAME, path='/docs')
gdurl_docs = client.GenerateAuthSubURL(authsub_docs,docs_gdataScope,secure=False, session=True)
cal_gdataScope = 'http://www.google.com/calendar/feeds'
authsub_cal = atom.url.Url('http', settings.HOST_NAME, path='/calender')
gdurl_cal = client.GenerateAuthSubURL(authsub_cal,cal_gdataScope,secure=False, session=True)
pic_gdataScope = 'http://picasaweb.google.com/data/'
authsub_pic = atom.url.Url('http', settings.HOST_NAME, path='/picasa')
gdurl_pic = client.GenerateAuthSubURL(authsub_pic,pic_gdataScope,secure=False, session=True)
yt_gdataScope = 'http://gdata.youtube.com'
authsub_yt = atom.url.Url('http', settings.HOST_NAME, path='/youtube')
gdurl_yt = client.GenerateAuthSubURL(authsub_yt,yt_gdataScope,secure=False, session=True)
ss_gdataScope = 'http://spreadsheets.google.com/feeds/'
authsub_ss = atom.url.Url('http', settings.HOST_NAME, path='/spreadsheets')
gdurl_ss = client.GenerateAuthSubURL(authsub_ss,ss_gdataScope,secure=False, session=True)
self.layout['content'] = self.view_dir + 'index.html'
params = {'gdurl_docs':gdurl_docs,'gdurl_cal':gdurl_cal,'gdurl_pic':gdurl_pic,'gdurl_yt':gdurl_yt,'gdurl_ss':gdurl_ss,'user':user,'layout':self.layout}
fpath = os.path.join(os.path.dirname(__file__),'layouts',self.layout_file)
html = template.render(fpath,params)
self.response.out.write(html)
class DocsHandler(webapp.RequestHandler):
layout_file ='layout.html'
view_dir = '../views/'
layout = {
'title':'GoogleDocumentデータアクセス',
'body_title':'GoogleDocumentデータアクセス',
'heder_title':'',
'heder_content':'',
'header':'header.html',
'footer':'footer.html',
}
def get(self):
user = users.get_current_user()
client = gdata.docs.service.DocsService()
gdata.alt.appengine.run_on_appengine(client)
session_token = None
# Find the AuthSub token and upgrade it to a session token.
auth_token = gdata.auth.extract_auth_sub_token_from_url(self.request.uri)
if auth_token:
# Upgrade the single-use AuthSub token to a multi-use session token.
session_token = client.upgrade_to_session_token(auth_token)
if session_token and users.get_current_user():
# If there is a current user, store the token in the datastore and
# associate it with the current user. Since we told the client to
# run_on_appengine, the add_token call will automatically store the
# session token if there is a current_user.
client.token_store.add_token(session_token)
elif session_token:
# Since there is no current user, we will put the session token
# in a property of the client. We will not store the token in the
# datastore, since we wouldn't know which user it belongs to.
# Since a new client object is created with each get call, we don't
# need to worry about the anonymous token being used by other users.
client.current_token = session_token
feed = client.GetDocumentListFeed()
self.layout['content'] = self.view_dir + 'gddocs.html'
params = {'feed':feed,'user':user,'layout':self.layout}
fpath = os.path.join(os.path.dirname(__file__),'layouts',self.layout_file)
html = template.render(fpath,params)
self.response.out.write(html)
~~~~~~省略~~~~~~~

以上。
私がつくったアプリ↓
協調型意思決定支援システム「○ 賛否両論 ×(ベータ版)」

http://sanpiryoron.appspot.com/

協調型プロジェクトタスク管理ツール「キャッチ&リリース(ベータ版)」

http://ctchandrls.appspot.com/

GoogleデータサービスAuthSub API利用サンプルアプリ