‘Google’ タグのついている投稿

「Google Maps API」と「GAE/P」の開発

2009年11月21日 土曜日

[ GAE Google App Engine ][ Phthon ][ Google Bigtable ][ Google Maps API ]
[ Google AJAX API ]
万歩計MAP作成にあたって、
そのほかに、つまづいたところを、以下にざっと。
■開発環境でのMapKEYについて
Google Maps APIを仕様するにあたって、
MapKEYの申請が必要になる。
当初、「http://manpokeimap.appspot.com/」で、
MapKeyを申請していたが、

http://localhost:8080 でKeyを取得すれば、GAE/Pの開発環境で

APIが利用できることが分かった。
アップロードの時には、KEYを変更することを忘れてはならない。
■ツールについて
Code Playground
のサンプルが非常に役に立った。
ソースを書きかえて、動作を確認できるのがうれしい。
ただ、GAEとの連携確認はできないよね。当然。
グーグルのJavaScriptツール集大成「Google Closure Tools」という記事より、
Google Closure Tools
というものも最近公開されたようだ。
今後、こういったものも利用すれば、
開発の効率は上がるかもしれない。
このほかに
今回、
Google Maps API デモ ギャラリーも役に立った。
JavaScriptであれば、ブラウザでソースがのぞけるので、
参考にしやすい。
■残念に思う点。
ルート表示が車でのルートになっているようだ。
徒歩表示に変更できることは確認した。
できるだけ早く対処する予定。
箱根駅伝(往路)コースを作ったけど
東名高速走ってるよ・・・。
細かいカスタマイズがイマイチ・・・。
日時は、他のアプリ同様、
UTC表示のままである。
私がつくったアプリ↓
協調型意思決定支援システム「○ 賛否両論 ×(ベータ版)」

http://sanpiryoron.appspot.com/

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

http://ctchandrls.appspot.com/

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

DAYS 16 AJAXとGAEの分かれ道

2009年11月20日 金曜日

[ GAE Google App Engine ][ Python ][ Google Bigtable ][ Google Maps API ]
[ Google AJAX API ]
万歩計MAP
コースを作成する時ルートを表示するのは、AJAX、
スタート地点と、ゴール地点をBigtableに保存する時は、GAEが動く。
http://code.google.com/apis/ajax/playground/#map_directions_advanced
をコピーしただけの状態であれば、
FORMには「onsubmit」が使われていたが、
Javascriptの動作と、Bigtableに保存する動作を分岐させるために
「onclick」を使った。
今回、ここを考えるのを一番苦労した。
最善ではないのかもしれない。
変更点は以下の通り。

<form action="#" onsubmit="setDirections(this.from.value, this.to.value, this.locale.value); return false">
・
・
・
<input name="submit" type="submit" value="Get Directions!" />

を「onclick」を使用して、以下のように変更。

・
・
<form id="form" name="form" method="" action="#" >
・
・
・
<input name="submit1" type="button" value="地図で確認!" onclick="setDirections(document.form.frompoint.value, document.form.topoint.value, document.form.localeset.value); return false"/>
<input name="submit2" type="button" value="保存する" onclick="goGAEdata();"/>
・
・

また、
GAEへデータを保存するのに、Javascriptで「goGAEdata()」を作成し動作させた。

・
・
function goGAEdata(){
document.form.method = "post";
document.form.action = "/mycourse/add";
document.form.submit();
}
・
・

一番どうするか時間がかかったが、
あまり納得がいっていない。
もうちょっとなんとかならんもんかと思う。
私がつくったアプリ↓
協調型意思決定支援システム「○ 賛否両論 ×(ベータ版)」

http://sanpiryoron.appspot.com/

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

http://ctchandrls.appspot.com/

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

DAYS 15 オーロラソース

2009年11月19日 木曜日

[ GAE Google App Engine ][ Python ][ Google Bigtable ][ Google Maps API ]
[ Google AJAX API ]
ケチャップとマヨネーズを混ぜたソースを「オーロラ」ソースというらしい。
今回、「Google Maps API
は、JavaScriptである。
で、私のGAEアプリはGAE/Pythonで構築している。
GAE/Javaの方が、相性がいいのかもしれないとか思ったが、
とりあえず、GAE/Pythonですすめた。
恐ろしいことが起きた。
JavaScriptソースの中に、pythonソースが混ざっている。
「JavaScriptソースの中に、javaソース」
の方が大変なんだろうか?
私には判断できないのだが・・・。
どう見ても「オーロラ」のように綺麗なソースにはなりえないことを確信した。
以下、10行目の {{frompoint}} と {{topoint}} と {{localeset}} が、GAE/Pythonで渡すパラメータ。

・
・
・
function initialize() {
if (GBrowserIsCompatible()) {
map = new GMap2(document.getElementById("map_canvas"));
gdir = new GDirections(map, document.getElementById("directions"));
GEvent.addListener(gdir, "load", onGDirectionsLoad);
GEvent.addListener(gdir, "error", handleErrors);
setDirections("<span style="color: #f00000;">{{frompoint}}</span>", "<span style="color: #f00000;">{{topoint}}</span>", "<span style="color: #f00000;">{{localeset}}</span>");
}
}
・
・
・

http://code.google.com/apis/ajax/playground/#map_directions_advanced

をカスタマイズをカスタマイズしたのだが、
Javascriptの変数に、「from」が使われているが、
「from」はPythonの予約語なので、「frompoint」にした。。
もっと手の込んだアプリになったら、
こんなことがたくさん起きてしまうと
考えるだけで怖い。
しばらくして、メンテナンスなんかした時に、
「間違ってるじゃん」って書きなおす
or
「こんな文法あったっけ?」って調べる
無限ループ。
無限ループ。
無限ループ。



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

http://sanpiryoron.appspot.com/

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

http://ctchandrls.appspot.com/

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

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利用サンプルアプリ