happy facebook developer
DESCRIPTION
Facebook APIsTRANSCRIPT
HAPPY FACEBOOK DEVELOPER
OUTLINE
• Self-Introduction • History and Trends• The Resource we need to know• What Facebook Provide Now• What languages We use in this offering • Add Facebook to my site• Apps on Facebook.com• Mobile apps
SELF-INTRODUCTION
• Eric Chuang / ddsakura
INTRODUCTIONFacebook
HISTORY AND STATICS
2004/2 Mark Zuckerberg launch Facebook
HISTORY AND STATICS
2007/10 Facebook reaches over 50 million active users2004/2 Mark Zuckerberg launch Facebook
HISTORY AND STATICS
2008/8 Facebook reaches over 100 million active users2007/10 Facebook reaches over 50 million active users2004/2 Mark Zuckerberg launch Facebook
HISTORY AND STATICS
2009/9 Facebook reaches over 300 million active users2009/2 Facebook reaches over 200 million active users2008/8 Facebook reaches over 100 million active users2007/10 Facebook reaches over 50 million active users2004/2 Mark Zuckerberg launch Facebook
HISTORY AND STATICS
2010/2 Facebook reaches over 400 million active users2009/12 Facebook reaches over 350 million active users2009/9 Facebook reaches over 300 million active users2009/2 Facebook reaches over 200 million active users2008/8 Facebook reaches over 100 million active users2007/10 Facebook reaches over 50 million active users2004/2 Mark Zuckerberg launch Facebook
HISTORY AND STATICS
全球有四億多會員,台灣則有 650萬
HISTORY AND STATICS
有50% 的會員,每天會造訪 Facebook
HISTORY AND STATICS
所有會員每個月花超過 5000 億分鐘在 Facebook 上
HISTORY AND STATICS
Facebook 上有 1.6 億個物件與會員進行互動
HISTORY AND STATICS
Facebook 有超過 70 種語系版本
HISTORY AND STATICS
有約 70% 的 Facebook 會員來自美國以外
HISTORY AND STATICS
有超過 100 萬個網站和 Facebook 整合
HISTORY AND STATICS
Facebook 有超過 55 萬個 Apps
HISTORY AND STATICS
每月有 70% 的會員用使用 Apps
HISTORY AND STATICS
有超過 100 萬的會員透過手機連到 Facebook
HISTORY AND STATICS
Sony Pictures has released the first trailer for the upcoming movie, “The Social Network”, which is loosely based (sensationalized) on the history of Facebook
http://www.thesocialnetwork-movie.com/http://www.youtube.com/watch?v=mWoUgftTj3Y
The Interface of Facebook
The Interface of Facebook
The Interface of Facebook
The Interface of Facebook
THE RESOURCE WE NEED TO KNOW
THE RESOURCE WE NEED TO KNOW
• Facebook Developer Wiki o http://wiki.developers.facebook.com/index.php/Main_Page
• Facebook developers Site o http://developers.facebook.com/
• Developer Blogo http://developers.facebook.com/blog/
• All Facebooko http://www.allfacebook.com/
• Inside Facebooko http://www.insidefacebook.com/
• http://www.facebook.com/developers/• Tools
o Firefox Firebugo http://developers.facebook.com/tools/
WHAT LANGUAGES WE USE IN THIS OFFERING
• Javascript• PHP• And we will also take a look at Facebook iPhone API
WHAT LANGUAGES WE USE IN THIS OFFERING
• But We Don’t discuss the skill for JavaScript, PHP, Objective-C, etc.
Big Event
• f8 developer conference on April 21, 2010.
WHAT FACEBOOK PROVIDES NOW
• Facebook for Website• Apps on Facebook.com• Mobile Apps
ADD FACEBOOK TO MY WEBSITEFacebook
ADD FACEBOOK TO MY WEBSITE
• Social Plugins• Single Sign-on• Graph API• Open Graph Protocol• Analytics• Platform showcase
SOCIAL PLUGINSFacebook
SOCIAL PLUGINS
SOCIAL PLUGINS
• The easiest way to get started with Facebook Platform.
• We Can Use iframe or XFBML method • Sample Code (iframe) <iframe
src="http://www.facebook.com/widgets/like.php?href=http://example.com" scrolling="no" frameborder="0" style="border:none; width:450px; height:80px"></iframe>
Demo
SINGLE SIGN-ONFacebook
Single Sign-on
• Oauth 2.0 protocolo http://tools.ietf.org/html/draft-ietf-oauth-v2-08o http://hueniverse.com/2010/05/introducing-oauth-2-0/
• We Can get basically:o All general information: like name, profile picture, gender and network.
• We can get moreo Ask extended Permissono http://developers.facebook.com/docs/authentication/permissions
• JavaScript SDK is a simple way
<div id="fb-root"></div> <script src="http://connect.facebook.net/en_US/all.js"></script> <script> FB.init({appId: 'your app id', status: true, cookie: true, xfbml: true}); FB.Event.subscribe('auth.sessionChange', function(response) { if (response.session) { // A user has logged in, and a new cookie has been saved } else { // The user has logged out, and the cookie has been cleared } }); </script>
Single Sign-on How to and Flow
• Register Our Appo http://tools.ietf.org/html/draft-ietf-oauth-v2-08o http://hueniverse.com/2010/05/introducing-oauth-2-0/
• Redirect the user to https://graph.facebook.com/oauth/authorize with client_id
• After the user authorizes your application, Facebook redirects the user to the callback URL you specified with the access token in the URL fragment:
• Use the access token returned by the request above to fetch data from the Graph API on behalf of the user.
Extended Permission
• Register Our Appo http://tools.ietf.org/html/draft-ietf-oauth-v2-08o http://hueniverse.com/2010/05/introducing-oauth-2-0/
• http://developers.facebook.com/docs/authentication/permissions
GRAPH APIFacebook
Register Apps
• http://www.facebook.com/?ref=logo#!/developers/apps.php
Graph API (1) - get data
• https://graph.facebook.com/ID
Graph API (2) - get data
• https://graph.facebook.com/ID/CONNECTION_TYPE
Graph API (3) - selection, Introspection
• https://graph.facebook.com/ID?fields=A,B,C...• https://graph.facebook.com/?ids=XXX,YYY
Graph API (4) POST
• We can publish to the Facebook graph by issuing HTTP POST requests to the appropriate connection URLs
Graph API (5) Delete
• We can delete objects in the graph by issuing HTTP DELETE requests to the object
• DELETE https://graph.facebook.com/ID?access_token=... HTTP/1.1
OR
• https://graph.facebook.com/COMMENT_ID?method=delete
Graph API (6) Search
• We can search over all public objects• https://graph.facebook.com/search?
q=QUERY&type=OBJECT_TYPE• For Example
All public posts: https://graph.facebook.com/search?q=watermelon&type=postPeople:https://graph.facebook.com/search?q=mark&type=userPages:https://graph.facebook.com/search?q=platform&type=pageEvents:https://graph.facebook.com/search?q=conference&type=eventGroups: https://graph.facebook.com/search?q=programming&type=group
Graph API (7) Tool
• Graph API referenceo http://developers.facebook.com/docs/reference/api/
Graph API (8) Tools
• CURL• Javascript
OPEN GRAPH PROTOCOLFacebook
Introduction
Introduction – from insidefacebook.com
Getting Start
Tool: URL Linter
• http://developers.facebook.com/tools/lint/
Administering our page
Location Meta Data
Analytics
• http://www.facebook.com/insights/
ShowCase
JAVASCRIPT SDKFacebook
JavaScript SDK(1)
•The JavaScript SDK enables you to access all of the features of the Graph API via JavaScript•The JavaScript SDK is also necessary to use the XFBML •Must register your application.•The SDK is open source and is available on http://github.com/facebook/connect-js
JavaScript SDK(2)
•Core Methods•Event Handling•XFBML Methods•Data Access Utilities•Canvas Methods
JavaScript SDK(3) – Core Methods
•FB.apiMake a API call
<script>FB.api('/me', function(response) { console.log(response);});</script>
JavaScript SDK(4) – Core Methods
•FB.getLoginStatusFind out the current status from the server, and get a session if the user is connected.
<script>FB.getLoginStatus(function(response) { if (response.session) { alert('Coneected'); } else { alert('No Coneected'); }});</script>
JavaScript SDK(5) – Core Methods
•FB.loginLogin/Authorize/Permissions.
<button id="fb-login">Login</button><script>document.getElementById('fb-login').onclick = function() { FB.login(function(response) { Log.info('FB.login callback', response); if (response.session) { Log.info('User is logged in'); } else { Log.info('User is logged out'); } });};</script>
JavaScript SDK(6) – Core Methods
•FB.logoutLogout the user in the background.
<button id="fb-logout">Logout</button><script>document.getElementById('fb-logout').onclick = function() { FB.logout(function(response) { alert('logout!'); // user is now logged out });};</script>
JavaScript SDK(7) – Core Methods
•FB.uiMethod for triggering UI interaction with Facebook as IFrame dialogs or popups, like publishing to the stream, sharing links.
<script> var share = { method: 'stream.share', u: 'http://www.cht.com.tw/' };
FB.ui(share, function(response) { console.log(response); });</script>
JavaScript SDK(8) – Event Handling
FB.Event.subscribeSubscribe to a given event name, invoking your callback function whenever the event is fired.
<script> FB.Event.subscribe('auth.sessionChange', function(response) { // do something with response.session }); </script>
JavaScript SDK(9) – Event Handling
FB.Event.unsubscribeRemoving a subscriber is basically the same as adding one
<script> var onSessionChange = function(response) { // do something with response.session };
FB.Event.subscribe('auth.sessionChange', onSessionChange);
FB.Event.unsubscribe('auth.sessionChange', onSessionChange); </script>
JavaScript SDK(10) – Data Access
FB.Data.query•Removing a subscriber is basically the same as adding one
FB.Data.waitOn•Wait until the results of all queries are ready
<script> var onSessionChange = function(response) { // do something with response.session };
FB.Event.subscribe('auth.sessionChange', onSessionChange);
FB.Event.unsubscribe('auth.sessionChange', onSessionChange); </script>
JavaScript SDK(11) - Canvas Methods
FB.Canvas.setAutoResize•Starts or stops a timer which resizes your iframe every few milliseconds.
FB.Canvas.setSize•Tells Facebook to resize your iframe.
APPS ON FACEBOOK.COMFacebook
APPS ON FACEBOOK.COM
ARCHITECTURE
WHAT FACEBOOK PROVIDES NOW
• FBML Canvas Applications Information Flow
WHAT FACEBOOK PROVIDES NOW
• Websites and IFrame Canvas Applications Information Flow
Register facebook application
Register facebook application - 基本資料
Register facebook application – 驗證
參數 說明Installable to? 什麼可以使用應用程式,
共有兩種選擇,分別是個人檔案和粉絲專頁。
Post-Authorize Callback URL
當使用者第一次新增應用程式後,呼叫的網址。
Post-Remove Callback URL 當使用者移除應用程式後,呼叫的網址。
Register facebook application – 個人檔案
參數 說明標籤名稱 顯示在個人檔案頁籤的名稱。
標籤網址 當點選頁籤時所載入的網址。
Post-Remove Callback URL 當使用者移除應用程式後,呼叫的網址。
Register facebook application – 個人檔案
Register facebook application – 個人檔案
參數 說明發佈文字 位於朋友的個人檔案頁面中發佈器所顯
示之標題文字。
發佈回呼網址 當在朋友的個人檔案發佈資訊時所呼叫的網址。
自我發佈文字 位於使用者本人的個人檔案頁面中發佈器所顯示之標題文字。
自我發佈回呼網址 當在使用者本人的個人檔案發佈資訊時所呼叫的網址。
Register facebook application – 畫布參數 說明
畫布頁面網址 設定將應用程式的畫布網址,基本上,這算是應用程式的首頁網址。只要沒有其他應用程式指定的字串,我們可以將該字串設定為畫布網址。
Canvas Callback URL 應用程式真正的網址。
Post-Authorize Redirect URL
當使用者第一次確認應用程式導向的頁面,預設值為畫布頁面網址。
呈現方法 可選則 FBML 或 Iframe 。
IFrame 大小 當選擇 IFrame 時可設定其大小。
畫布寬度 當選擇畫布時可設定其大小。
Authentication
Canvas applications use cookies to get user authentication information. The cookie includes a signature for all the values as the argument sig.
Integration Points
• Stream publishing• Requests• Bookmarks and Counters• Application and Games dashboards• Profile tabs
Stram publishing
Request
Using FBML tags you can render request forms and friend selectors.
Bookmark, Counters, Game Dashboard, Profile Tab
<fb:bookmark></fb:bookmark>
FACEBOOKQUERYLANGUAGE
FQL(1)
• Facebook Query Language • Enables we to use a SQL-style interface to query the data• https://api.facebook.com/method/fql.query?query=QUERY.• Table
FQL(2) – Testing Tool
• http://developers.facebook.com/docs/reference/rest/fql.query
FQL(3) – 支援基本的運算字參數 說明
+ 加法
- 減法
* 乘法
/ 除法
> 大於
< 小於
>= 大於等於
<= 小於等於
= 等於
AND 及
OR 或
NOT 不是
FQL(4) – 支援的函式參數 說明
now() 取得現在的時間。
rand() 產生亂數。
strlen(string) 計算字串長度。
concat(string, ...) 合併本函式中的所有字串。
substr(string, start, length) 根據字串開始位置 start 和取得長度 length 兩個參數,取得 string 字串的部份文字。
strpos(haystack, needle) 搜尋 haystack 字串,找出該字串中第一次出現 needle 字串的位置,若找不到符合 needle字串的文字,則回傳 -1 。
lower(string) 將字串轉換成小寫。
upper(string) 將字串轉換成大寫。
FQL(5) – Table : link_stat
• Query this table to return detailed information from your Facebook Share implementation
• SELECT share_count, like_count, comment_count, total_count,click_count FROM link_stat WHERE url="http://www.yahoo.com"
FQL(6) – Table : friend
• Query this table to determine whether two users are linked together as friends.
• 確認 uid1 跟 uid2 是否為朋友,若雙方不是朋友,將會取得空字串。• select uid1,uid2 from friend where uid1=4 and uid2=5
• 取得 uid1 的朋友清單• select uid1,uid2 from friend where uid1= 登入者的 UID
FQL(7) – Tables
• stream• SELECT actor_id, message FROM stream WHERE source_id = <user
id> limit 5• photo_tag
• SELECT pid FROM photo_tag WHERE subject=$uid• photo
• SELECT src_big FROM photo WHERE pid IN (• SELECT pid FROM photo_tag WHERE subject=$uid• )
FBML
FBML(1)
• FBML enables you to build Facebook applications that deeply integrate into a user's Facebook experience.
FBML(2)•Tools•User/Groups•Notifications and Requests•Platform Internationalization•Status Messages•Page Navigation•Wall•Visibility on Profile•Profile-specific•Misc•Editor Display•Embedded Media•Dialog•Additional Permissions•Social Widgets•Message Attachments•Forms
FBML(3)
<fb: 語法名稱 參數一 =" 參數值 " 參數二 =" 參數值 " ‧‧‧> 傳入內容 </fb: 語法名稱 >
FBML(4)
FBML(5)
•http://developers.facebook.com/docs/reference/fbml/•http://developers.facebook.com/tools/console/
FBML(6)
<fb:bookmark></fb:bookmark><fb:comments xid="titans_comments" canpost="true" candelete="false" returnurl="http://apps.facebook.com/myapp/titans/"></fb:comments>
OLD REST API
• The old REST API is the previous version of the Graph API. • If we are new to the Facebook Platform, Facebook recommend you
use our new Graph API instead.
• Administrative Methods• Login/Auth Methods• Data Retrieval Methods• Publishing Methods• Facebook Connect Methods• Mobile Methods• Dashboard API Methods• Events API Methods• Custom Tags API Methods
https://api.facebook.com/method/xxxx?access_token=
MOBILE APPS
• iPhone SDK• Android SDK
MOBILE APPS - iPhone