TShopping

 找回密碼
 註冊
搜索
查看: 2357|回復: 4
打印 上一主題 下一主題

[教學] Facebook API Publisher 使用 Attach 附件服務增加發佈塗鴉牆的效果

  [複製鏈接]
跳轉到指定樓層
1#
發表於 2012-4-2 16:26:21 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
有時希望可以讓使用者在分享文字或連結時,能自動帶出一些效果,這時候我們需要的就是 Publisher 服務。例如當輸入 YouTuBe 影片連結時,系統會自動幫我們嵌入 YouTuBe 的顯示頁面,而不再只是簡單的 link 樣貌,此時原理即是將使用者輸入的資料,進行分析再轉換成新的呈現方式。
然而,目前 Facebook 平台開放的狀態還沒讓開發者如此便利,但有個間接使用的方式,那就是發表時以 Attach(附件) 來呈現。關於 Attach 的設定方式如下:
Setup
  • My Applications > Edit Settings > Profiles > Profile Publisher
    • Publish
      • Text
      • Callback URL
    • Self-Publish
      • Text
      • Callback URL
其中可分成兩類,一種是在別人的塗鴉牆留言時,另一種則是在自己的塗鴉牆留話。分別都需要填寫兩項資訊,其中 Text 代表在 Attach(附件) 顯示的按鈕名稱,如:加增表情符號。 Callback URL 則是當使用者按下按鈕時,系統會去這個位置要資料來呈現。實作上要留意,那個 Callback URL 回傳的資料要以 JSON 格式回來。
至於 Facebook 去 Callback URL 進行撈資料時,帶有以下參數資訊:
  • fb_sig_api_key: Your application's API key.
  • fb_sig: A signature using your application's secret key to encrypt the request.
  • fb_sig_in_canvas: This parameter is always false or 0 because the Publisher is not a canvas page.
  • fb_sig_request_method: This is always a POST method.
  • fb_sig_locale: This is the user's locale.
  • fb_sig_time: The time that the request was made.
  • fb_sig_added: Indicates whether the user has authorized (agreed to your Terms of Service) the application.
  • fb_sig_profile_user: Indicates the user whose profile is being published to.
  • fb_sig_user: The ID of the user interacting with the Publisher.
  • method: Indicates if the Publisher is getting the application's Publisher interface or getting the Feed story.
  • 等等‥
只是,依舊沒有使用者當下輸入的資訊,這讓我有一點小失望,這也可能基於一些隱私或安全性的考量吧?剩下的我只好有空再來摸索啦!但是,目前開放的平台特色仍可以做出不錯的效果喔!
發佈塗鴉牆的效果


點選播放的畫面
簡單的 Callback 程式碼,其中 base.php 則是處理 Facebook API 的初始化,而 publisher_getFeedStory 部份則是直接用上頭 Facebook - Publisher 提到的範例。
  1. <?php
  2. require( 'base.php' );
  3. $data = array();
  4. $data['content'] = array();

  5. $out = '';
  6. foreach( $_REQUEST as $k => $v )
  7.         $out .= "[$k] => [$v]<br>";
  8. if( !isset( $_REQUEST['method'] ) || $_REQUEST['method'] == 'publisher_getInterface'  )
  9. {
  10.         $data['content']['fbml'] = json_encode( $out );
  11.         $data['content']['oublishEnabled'] = true;
  12.         $data['method'] = 'publisher_getInterface';
  13. }
  14. else
  15. {
  16.         $data['content']['attachment'] = array();
  17.         $data['content']['attachment']['name'] = 'ninja cat';
  18.         $data['content']['attachment']['href'] = 'http://www.youtube.com/watch?v=muLIPWjks_M';
  19.         $data['content']['attachment']['caption'] = '{*actor*} uploaded a video to www.youtube.com';
  20.         $data['content']['attachment']['description'] = 'a sneaky cat';
  21.         $data['content']['attachment']['properties'] = array();
  22.         $data['content']['attachment']['properties']['category'] = array();
  23.         $data['content']['attachment']['properties']['category']['text'] = 'pets';
  24.         $data['content']['attachment']['properties']['category']['href'] = 'http://www.youtube.com/browse?s=mp&t=t&c=15';
  25.         $data['content']['attachment']['properties']['ratings'] = '5 stars';
  26.         $data['content']['attachment']['media'] = array();
  27.         $data['content']['attachment']['media'][0]['type'] = 'video';
  28.         $data['content']['attachment']['media'][0]['video_src'] = 'http://www.youtube.com/v/fzzjgBAaWZw&hl=en&fs=1';
  29.         $data['content']['attachment']['media'][0]['preview_img'] = 'http://i2.ytimg.com/i/uZp-cf0yOTqQEOuKGGnocg/1.jpg';
  30.         $data['content']['attachment']['media'][0]['video_link'] = 'http://www.youtube.com/watch?v=muLIPWjks_M';
  31.         $data['content']['attachment']['media'][0]['video_title'] = 'ninja cat';
  32.         $data['method'] = 'publisher_getFeedStory';
  33. }
  34. echo json_encode( $data );
  35. ?>
複製代碼

其中,上述發佈用的 template 允許四種 type ,分別為 image , flash, mp3, vedio ,細節請參考 Facebook - Attachment (Streams)
參考資料

 

臉書網友討論
2#
 樓主| 發表於 2013-2-1 19:30:58 | 只看該作者
牛X海海!!!

版主招募中

3#
發表於 2013-3-8 02:18:26 | 只看該作者
4#
發表於 2014-7-3 15:16:35 | 只看該作者
我喜欢,请大家鼓掌支持,谢谢











bjcars.net


5#
發表於 2014-11-5 18:31:47 | 只看該作者
这是真的吗?太好了,谢谢您啊


*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-5-5 09:24 , Processed in 0.061202 second(s), 17 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表