這篇算筆記, 有可能會有一些失落環節在, 主要從create Facebook application到可以在local端執行

Facebook這月稍早時跟Heroku合作, 讓建立一個Facebook應用程式(含後端)更加方便: http://developers.facebook.com/blog/post/558/ (有些步驟可以從這看)

我選了Node.js當做開發的平台, 以下就是我的步驟:

建立Facebook application

首先到Facebook application page https://developers.facebook.com/apps/ 建立一個新的應用程式

跟以往有點不太一樣的是, 在Application settings裡面多了一個"Cloud Services" -

_2011-09-21_4

目前只有Heroku可以選, 我猜以後搞不好會有更多合作對象吧

選了Provider之後, 接下來就要選擇平台, 目前有PHP, Python, Ruby, Node.js可選, 選擇算蠻多的了, 這邊選Node.js

_2011-09-21_4

經過一些有的沒的之後, 就會有這畫面, 這邊已經完成這個應用程式的基本雛形了

_2011-09-21_4

設定你的heroku應用程式

到 https://api.heroku.com/myapps 去設定你的應用程式, 在這邊你可以修改應用程式名稱, 不過比較麻煩的是, 這邊的修改並不會同步回Facebok, 因此修改後還是需要回Facebook去更改相關設定:

_2011-09-21_4

在你的電腦執行

一般在程式沒完成前大多都不會想直接佈署上去, 能在自己電腦先執行驗證過是比較容易抓蟲的

以下是先需要安裝的

heroku command line -

heroku是用gem安裝的, 所以安裝前要先確認你電腦有沒安裝Ruby, heroku安裝方法很簡單, 只要執行 “gem install heroku”

安裝好後先用"heroku keys"看看有沒存在的key, 有的話可能會讓之後要用git抓資料有問題, 有的話用"heoku keys:remove"先移除, 這樣login會產生新的public key

用"heroku login"登入heroku, 第一次使用可能會要求產生public key

登入後就可以用"git clone [email protected]:ff8.git"抓下原始碼(ff8是heroku application name)

node.js -

這當然是必須安裝的(在這例子), 如果是在mac上, 又是brew的使用者, 那只要用"brew install node"即可

npm (node package manager) -

安裝方式很簡單, 只要"curl http://npmjs.org/install.sh | sh"

安裝好後, 在git clone下來的目錄下"npm install", 它自然會裝好所有所需的package

foreman -

文件裡面有建議裝, 不過由於這範例只是一個單純的web, 並沒其他worker, 可以不裝

設定Facebook application

因為要在本地端執行而不是heroku的雲, 所以要把url都指向本地端, 像這樣:

_2011-09-23_5
設定環境變數

export FACEBOOK_APP_ID=122348222122778

export FACEBOOK_SECRET=1ba1beed9f7b5be9192bf4540c231234

export PORT=5000

(我跑在5000)

如果使用foreman, 就把這些寫在.env中

執行

“node web.js"就可以將server跑起來(或是foreman start), 然後到http://localhost:5000/就可以看到結果 

_2011-09-23_4
_2011-09-23_4

Facebook今天發表的Timeline真是令人興奮的功能呀

現在應該再也沒人說很難用Facebook當日記了(雖然我講日記這概念講很久都沒去實現他)…

剛剛我的Timeline也啟用了, 這真的會讓我花很多時間在上面的東西呀…

_2011-09-23_4

連Game都可以有Timeline… XD

According to Facebook mobile development document (Android), you need to generate a key hash for your application in order to apply Facebook SSO(Single Sign on).

Here is the formal way to do this:

keytool -exportcert -alias androiddebugkey -keystore ~/.android/debug.keystore | openssl sha1 -binary | openssl base64

But sometimes you won’t have a tradtional key store especially when building with Android open sources. Keys in Android open sources are in pk8 format. In order to generate key hashes with these keys, you need to tranfer them into a pk12 key store.

I created another way to generate keyhash without keytool and openssl. Here is the source codes: FacebookKeyHashGen

This program get package sigature directly from package itself. 

本來是放在我EverNotes內的, 貼一些出來好了, 無聊時玩玩的東西, 沒優化過:

  • 共同喜歡的Page : select name from page where page_id in (select page_id from page_fan where uid=friend_uid and page_id in (select page_id from page_fan where uid=me()))
  • 共同朋友: select name from user where uid in (select uid2 from friend where uid1=me()) and uid in (select uid2 from friend where uid1=friend_uid)
  • 同時都出現的照片: select src from photo where pid in (select pid from photo_tag where subject=friend_uid) and pid in (select pid from photo_tag where subject=me())
  • 屬於某Group的照片: select src from photo where pid in (select pid from photo_tag where subject=group_id)
  • 共同參加的活動: select name from event where eid in (select eid from event_member where uid=me() and rsvp_status=‘attending’) and eid in (select eid from event_member where uid=friend_id and rsvp_status='attending’)
  • 都去過的地方(僅限於自己checkin不包含被tag): select name from place where page_id in (select page_id from checkin where author_uid=me()) and page_id in (select page_id from checkin where author_uid=friend_uid)
  • 喜歡過的某人的post:  select message from stream where post_id in (select post_id from like where post_id in (SELECT post_id FROM stream WHERE source_id=friend_uid) and user_id=me())
  • Comments on someone’s post: select text from comment where post_id in (SELECT post_id FROM stream WHERE source_id=friend_uid) and fromid=me()

其中"me()“是自己, 有些FQL裡的"me()"可以代換成另一個人的uid

    替照片上的每個人都加上標籤(tag)是一個蠻好用的功能, 這可以方便你找到有某人的照片, 或是一群人在某時的合照, 如果善加利用是相當好用的功能, 目前主流的幾個相片服務像是Flickr, Facebook, Picasa等等, 都有這樣的功能

    其中以Picasa的功能最為先進, 它可以自動幫你把你所有照片裡的朋友都挑出來標示, 不像Flickr跟Facebook就只能手動

    如果每張照片都只能手動標示的話, 標示完所有的照片是很累人的, 更何況可能還有很多未標示的舊照片, 就這點來說, Picasa就強勁很多, 至於Facebook和Flickr呢? 所幸有Face.com

    Face.com是一個做自動標示的服務, 其實這樣講有點狹隘, 自動標示照片的服務只是它其中一個產品 - PhotoTagger, PhotoTagger的用處就有點像Picasa做的一樣, 自動幫你把照片的人物找出來做標示:

    _2011-05-01_8
    當然準確度不會到100%那麼高啦, 不過加上手動輔助的話, 已經可以節省不少功夫了

    此外還有PhotoFinder和CelebrityFindr….不過這些並不是重點, 它真正比較強大的是, 它乾脆把它的Face detection和Face recogintion 的API開放出來, 讓你可以利用它們的雲端運算做出自己的應用

    它的API是以REST的形態提供的, 支援的後端服務有Facebook, Flickr, Twitter, 基本的API也大致相當完整, train, detect, recongnize, tag等等, 如果是做Facebook相關的應用, 甚至可以省略過train的部份, 就可以達到辨識的效果

    當然, 剛剛的應用像是PhotoTagger都是以拍完後的照片為目標而做的, 如果拍照完後馬上就可以找出有哪些人可以tag的話, 那就更棒了

    為了實驗這個我寫了一個簡單的Android app - Face.me , 只要拿著Android手機對著你朋友拍一張(按螢幕畫面), 它就會利用Face.com去找出你這朋友的名字 (可以從連結下載APK安裝, 因為Camera部分不熟, 寫的不太好, 可能會有bug, 就不open source了 :P) 

    這App利用了一個open source的Face.com的Java lib叫face4j, 基本上這lib移植到Android上並不困難, 它用到一些apache commons, http的library, 只要把這些含入就可以

    要開發這個, 首先你必須要有Facebook API key和Face.com的API key, Face.com的API key可以到這裡註冊個新的, 另外還得把Facebook的API key和secret註冊到Face.com上(看你信不信任它囉)

    Facebook API的部份, 我是用Facebook Android SDK去開發的, 其實也沒用到幾個API, 大致上只有login和取得自己的UID而已

    另外由於face4j在reconigize這個method只支援檔案跟url兩種方式, 我另外修改了一個支援input stream的:

    https://gist.github.com/950492.js?file=gistfile1

    剩下的部份就簡單了, 在Camera.takePicture的第三個參數的PictureCallback.onPictureTaken裡加上: