顯示具有 GAE 標籤的文章。 顯示所有文章
顯示具有 GAE 標籤的文章。 顯示所有文章

2011年1月21日 星期五

gae facebook開發

debug
google appengine unknown url type: 'https'

gae 連 fb facebook問題
官方python sdk的facebook.py
用的是import urllib
但請用import urllib2去抓https的資料


file = urllib2.urlopen("https://graph.facebook.com/" + path + "?" +
                              urllib.urlencode(args), post_data)
#file = urlfetch.fetch("https://graph.facebook.com/" + path + "?" +
#                      urllib.urlencode(args), post_data)

否則會一直錯下去喔!

2011年1月19日 星期三

GOOGLE APPENGINE gae 實作 YAHOO 帳號登入

這個主題好像繁體中文好像沒人寫,
反正我找這方面的SOLUTION時,
沒有看到,
幸運的在YAHOO DEVELOPER Social SDK上找到了方法
http://developer.yahoo.com/social/sdk/#python

所以就不需要自已去撈api重新撰寫gae上的yahoo帳號登入了,

有些地方要改正,
就沒有任何問題了

先下載 python的SDK
http://developer.yahoo.com/social/sdk/#python

解壓後 yahoo-yos-social-python\examples\appengine 這個目錄就是寫給gae run的,
不過還有一些部驟才會正常,

0.將聯外打通,內部gae run外部可以正常。記得對外ip!!!

1.先去 https://developer.apps.yahoo.com/
申請一個account,
並新增一個YAP(Web Base)取得Key

然後 我記得description 怎麼寫 都不會通過,
之後按取消就過了,
這可能是我的誤解,
不知是什麼原因,
大家研究一下。

2.取得Key後,
打開yosdemo.py
將

CONSUMER_KEY
CONSUMER_SECRET
APPLICATION_ID(在Key的上面)
CALLBACK_URL(對外ip)
填入吧!


3.可是這樣子還是不會成功的run!
之後將 \build\lib 目錄下的目錄copy至 appengine下,
然後將下面內容生成gmemsess.py 置於 目錄下


# gmemsess.py - memcache-backed session Class for Google Appengine
# Version 1.4
# Copyright 2008 Greg Fawcett 
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see .
import random
from google.appengine.api import memcache
_sidChars='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
_defaultTimeout=30*60 # 30 min
_defaultCookieName='gsid'
#----------------------------------------------------------------------
class Session(dict):
 """A secure lightweight memcache-backed session Class for Google Appengine."""
 #----------------------------------------------------------
 def __init__(self,rh,name=_defaultCookieName,timeout=_defaultTimeout):
  """Create a session object.
  Keyword arguments:
  rh -- the parent's request handler (usually self)
  name -- the cookie name (defaults to "gsid")
  timeout -- the number of seconds the session will last between
             requests (defaults to 1800 secs - 30 minutes)
  """
  self.rh=rh # request handler
  self._timeout=timeout
  self._name=name
  self._new=True
  self._invalid=False
  dict.__init__(self)
  if name in rh.request.str_cookies:
   self._sid=rh.request.str_cookies[name]
   data=memcache.get(self._sid)
   if data!=None:
    self.update(data)
    # memcache timeout is absolute, so we need to reset it on each access
    memcache.set(self._sid,data,self._timeout)
    self._new=False
    return
  # Create a new session ID
  # There are about 10^14 combinations, so guessing won't work
  self._sid=random.choice(_sidChars)+random.choice(_sidChars)+\
       random.choice(_sidChars)+random.choice(_sidChars)+\
       random.choice(_sidChars)+random.choice(_sidChars)+\
       random.choice(_sidChars)+random.choice(_sidChars)
  # Added path so session works with any path
  rh.response.headers.add_header('Set-Cookie','%s=%s; path=/;'%(name,self._sid))
 #----------------------------------------------------------
 def save(self):
  """Save session data."""
  if not self._invalid:
   memcache.set(self._sid,self.copy(),self._timeout)
 #----------------------------------------------------------
 def is_new(self):
  """Returns True if session was created during this request."""
  return self._new
 #----------------------------------------------------------
 def get_id(self):
  """Returns session id string."""
  return self._sid
 #----------------------------------------------------------
 def invalidate(self):
  """Delete session data and cookie."""
  self.rh.response.headers.add_header('Set-Cookie',
    '%s=; expires=Sat, 1-Jan-2000 00:00:00 GMT;'%(self._name))
  memcache.delete(self._sid)
  self.clear()
  self._invalid=True








4.最後,開啟網站會移至yahoo登入,登入會移回原來你的網站,看到自已的名字等資訊便大功告成了!!!

2010年8月27日 星期五

JSON GAE google appengine 吐血的特絑符號處理 換行符號 斜分號 等

JSON
吐血的特絑符號處理

1.換行符號:
會導致無法讀取JSON
GAE裡可在用template裡的linebreaksbr換成
2.斜分號 "\"在String裡會判斷錯,同樣導致無法讀取JSON,怪的是不見得一定會出現無法讀取的狀況,在local端做伺服時都正常,但一上線,就是掛~
在GAE裡可用urlencode先轉碼,然後輸出時,再用javascript 的 decodeURI再轉回來。

原以為如此如此就天下太平了,
但是一上線還是掛
    return urllib.quote(value) 
  File "/usr/lib/python2.6/urllib.py", line 1223, in quote 
    res = map(safe_map.__getitem__, s) 
KeyError: u'\xe3' 


urlencode轉碼失敗


然後
http://groups.google.com/group/google-appengine-python/browse_thread/thread/70b10f012ae33aed/996ecc33e7444cfc?#996ecc33e7444cfc


http://seewah.blogspot.com/2009/11/django-template-urlencode-unicode.html

上面有解,
不過還是不行,殘念~

結論就是存檔前先擋吧~
今天完全敗給 \^^/
可恥的一天

2010年6月8日 星期二

實作教學 google app engine GAE 開發 facebook app FB應用程式

去年曾經寫過一篇用GAE開發facebook app,

實作教學Facebook Application+JQuery + Google App Engine 初章.1


當時用的是pyfacebook,
也不過才半年多,

去年的那篇,
基本上可以把pyfacebook丟了,
目前在facebook上,
他們直接的針對GAE撰寫了新的SDK


參考http://developers.facebook.com/docs/

基本上,這些Server端的SDK,

主要是從cookie中取得你的身份,
並於底層中操作Graph API
這個Graph API其實是包著上述方法,
再從Server get url方式取得Data,
所有你需要的Data幾乎都可以從這個API來做呼叫,
執行效率和bug的錯誤比之前用pyfacebook好很多。

在python SDK 的 github上有一段sample,
你可以試著做看看。

GAE的部份,就不在贅述,基本上只要將facebook.py,example.py,example.html置於你的gae目錄下,上傳後,應該就可以順利執行了。

去年的facebook應用設計,
整個呼叫API的部份不再和PHP綁在一起,
目前書店裡關於facebook開發的書,
老闆頭很痛吧!


facebook改為Graph API的主要目地,
Wolke推測,應是在為不同平台、如mobile、TV...鋪路囉~


執行若有問題再留言討論吧!

2010年4月8日 星期四

實作教學Facebook Application+JQuery + Google App Engine 初章.1

想要研究一下這一塊,發現中文網頁,竟然沒什麼相關資料,

可能因為是阿共仔屏蔽了Facebook吧!!

那好,我就把我目前就研究到此的作法和心得寫一寫,

以免後進走太多冤妄路,

想要撰寫我標題所說的Facebook +JQuery+ GAE

你必需具備:

  1. HTML基礎
  2. Python基礎
  3. Google帳號和已認證的可用的GAE帳號
  4. GAE的架構
  5. Facebook的架構
  6. FBML,FBJS的撰寫


上述可參考上官林傑的 Google應用服務引擎開發實戰及這邊可參考 賽大的 Facebook與funP應用程式設計

Google應用服務引擎開發實戰

http://www.books.com.tw/exep/prod/booksfile.php?item=0010443092

Facebook與funP應用程式設計

http://www.books.com.tw/exep/prod/booksfile.php?item=0010445951

PS:這本用的是Facebook自行開發的PHP API,和我們要用的pyfacebook不同,

不過除了部份API不支援,其實大部份都是相通的,盡請安心服用。


Javascript基礎(初章暫不需)

Javascript書很多,本人推薦 JavaScript私房書 JavaScript私房書 <光碟1片 >

http://www.books.com.tw/exep/prod/booksfile.php?item=0010294368


JQuery基礎(初章暫不需)

我找不到覺得優的書,所以我都只直看網站的turtuial,不過歡迎大家推薦一下

IP分享器映射http port至你的電腦

各家分享器做法不同,請參考你的說明書


ok 重點來了..

本初章先將焦點放在如何在GAE上運行pyfacebook進而開發facebook的application

Pyfacebook基礎,網路神人團所撰寫的pyfacebook 用python撰寫的可以和facebook 溝通的Server端API可供GAE使用開發

pyfacebook:

http://github.com/sciyoshi/pyfacebook/

1.首先將 pyfacebook下載解壓後,存至gae目錄下

2.在pyfacebook目錄裡建置app.yaml

內容如下:

application: whatever

version: 1

runtime: python

api_version: 1

handlers:

- url: .*

script:main.py


主檔main.py

內容如下



# -*- coding: utf-8 -*-

import cgi
import sys, os
import wsgiref.handlers

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
import facebook
from facebook import FacebookError

FACEBOOK_API_KEY = '你的key' #如何申請請自行參閱,不詳述囉
FACEBOOK_SECRET_KEY = '你的key'
_DEBUG = True


class MainPage(webapp.RequestHandler):
def get(self):
#def post(self):
fb = facebook.Facebook(FACEBOOK_API_KEY, FACEBOOK_SECRET_KEY)
if fb.check_session(self.request) and fb.added:
pass
else:
url = fb.get_add_url()
self.response.out.write('<script language="javascript">top.location.href="' + url + '"</script>')
return


#get friend list begin
friend_ids = fb.friends.get()
friend_ids.append(fb.uid)

info = fb.users.getInfo(friend_ids, ['name', 'pic_square', 'uid'])
template_values={}
template_values={'info': info}
#get friend list end

for i in info:

self.response.out.write('<img src='+i['pic_square']+' />'+i['name']+'<br />')

def main():
application = webapp.WSGIApplication([('/',Mainpage)],debug=_DEBUG)
wsgiref.handlers.CGIHandler().run(application)

if __name__ == "__main__":
main()


執行一下你的dev_appserver.py --address=映射好的內納IP --port=80 demos/pyfacebook

(其實你也可以直接下appcfg.py上傳你的程式至GAE上,不過這樣初期開發會增加很時間成本)

設定你的facebook developer 你的應用程式

將Canvas URL:設定為你的外網IP(或是GAE的應用程式網址)

運行一下:

http://apps.facebook.com/你的facebook網址/
(請輸入你的facebook app 網址)

將 將!!!

你就會看到你的朋友列表了

預告:目前是使用iframe的方式,

第二節來說一下FBML好了

2010年3月13日 星期六

心願便利貼beta 1.0

願望...

又將是新年的開始....

你的心裡有什麼願望呢?

來貼上您的心願,

大家一起願望集氣吧!

http://apps.facebook.com/fbwishtwentyten/





後記:

撰寫方式:

GAE + pyfacebook + fbjqry

GAE存data

fbjqry做effect

GAE SDK要更新到最新版,不然一直會有奇怪的error

fbjqry本身只到0.2版

撰寫時有發現一些bug

fadeIn callback等不能執行...待大德debug

架構,

資料和css是分開的,

理論上要改成什麼版都可以吧!

過兩天將 心願便利貼,

改個版型 心牆 版,

等我吧~ 寶貝,

這個程式,應該可以玩到農曆過年前吧!

快過年時,再搞個龍山寺版好了~

滿天神佛都請來加持一下,

肯定心願會實現的!

哈!!!!!!





2009.1227

BUG:

IE6-IE8無法執行

FF fadeOut有時會失敗





2009.1228

debug:

ie可運行

BUG:

1.有時得到JSON DATA後,<--原因出自JSON data產生太慢,因為 getinfo這個api有時會等太久或失敗

轉換為網路原件很久

2.IE 更久..

3.CLICK MSG.val('')

4.CPU時間要想想如何減低...(要用memchche)

5.click should link to personal page.

6.js中文轉換亂碼

7.缺NOTIFICATION

8.自動轉址要用fb:redirect才正常

DEBUG:

3,5,6

2009.1230

想方設法於首頁改用FBML來減低gae的CPU TIME等待過久的問題