今早打算編寫新的 Template 時,在 Tools 頁面發現以下訊息:
Facebook will deprecate template bundles and their related API calls December 20, 2009.
Please start using stream attachments with stream.publish, FB.Connect.streamPublish, and Facebook.streamPublish instead.
這個衝擊說大不大說小不小!影響不大是因為我還沒很善用它,但我已經有點彈性疲乏啦,因為準備要塞進 Template 的資料,弄得很疲憊。不過,該做的正事還是要完成。
目的:
在 FBML 模式下,以 FBJS 達成過去 Facebook.showFeedDialog 的效果。
解法:
使用 Facebook.streamPublish 來代替,而原先的 template 部份將變成在 Code 裡。好處是可以少一次跟 Facebook Server 要資料吧。或許這也是 template 佔用資源而被拿掉的可能性??
除此之外,還需要用到 attachment 概念,就是以前寫在 template 上的資訊
程式碼:
<script type="text/javascript">
function do_post()
{
var attachment = {
'name':'Quiz',
'href':'http://apps.facebook.com/your_apps/',
'description':'good!',
'caption':'{*actor*} is very smart!',
'media':[
{
'type':'image',
'src':'http://upload.wikimedia.org/wikipedia/commons/thumb/0/06/Facebook.svg/200px-Facebook.svg.png',
'href':'http://zh.wikipedia.org/wiki/Facebook'
}
]
};
Facebook.streamPublish( '' , attachment , null , null , 'Message:' , null , false );
}
</script>
接著在適當地地方呼叫 do_post(); 吧!
- 以 click 呼叫
- <a href="#" onclick="do_post();return false;">Click Here!</a>
- 自動執行
- <script type="text/javascript">
do_post();
</script> - 記得這段 code 要擺在 function() do_post{ ... } 後頭才用喔
- <script type="text/javascript">
收工。
參考資料:
相關文章