SlideShare a Scribd company logo
+ Building Facebook Applications with Ruby Alex Koppel, 12/2010
WHY DEVELOP WITH FACEBOOK? Over 500 million users 50% of active users log on every day 150 million in USA 10 million in Germany Application Platform Over 550,000 applications Over 1,000,000 websites integrated with Facebook Over 150 million users use such FB integrations / month Huge audience, extensive Platform
WHAT CAN APPS OFFER USERS? Better interface to Facebook core functionality iPhoto, Wall moderation and publishing platforms Promotion of an existing service Netflix, Yelp, Goodreads Create a connection with fans of a brand Chase Community Giving, other branded apps Authentication Groupon, Kayak, Goodreads Many applications fall into multiple categories
WHAT KINDS OF APPS ARE THERE? Websites Your own site Complete control Javascript SDK Any level of integration Canvas Apps Tab Apps Mobile Apps Desktop Apps Hosted on facebook.com Less friction for users on the site Some limitations (size/etc.) FBML+FBJS => restrictions
WEBSITES Wherever, whatever Benefits for users A way to share activity Easy login Lightweight integration Social plugins (iframes) Javascript SDK only Heavyweight integration Javascript frontend Server backend
CANVAS APPS Live on Facebook iframe or FBML iframe ~ website FBML to be retired Less friction than off-FB apps Users stay on site Have to work within Facebook limits iframe container Fixed size
TAB APPS Live on Facebook Page Tight integration with Page (brand/product) Can help drive Liking Limitations FBML/FBJS only  (iframe in the future) Size limitation First load is anonymous
FACEBOOK INTEGRATION Both front- and back-end integration Browser handles tasks requiring interaction Login, permissions, publishing stories Server handles many API-related tasks Offline access, realtime updates, app management Persisting results Many tasks can be done by either server or client Authentication API calls  Let your need guide you
ACCESSING FACEBOOK
FACEBOOK AUTHENTICATION OAuth-based authentication scheme Token provides access to user info Multiple ways to authenticate Javascript API Redirect with OAuth code Signed request parameters Provided in request to tab and canvas apps Old proprietary auth scheme being deprecated
AUTHENTICATING WITH JAVASCRIPT iframe-based secure login prompt XFBML login button Programatic via Javascript Includes permissions if desired Browser gets OAuth token, user ID, expiration, etc.  Notified through callback and event Javascript sets signed cookie cookies Server libraries provided parsing Preferred method Easy for users Keeps people on your site
AUTHENTICATING WITH REDIRECTS Send user to login page on facebook.com User redirected to app’s callback with OAuth code App server requests token using code and secret Server gets OAuth token and expiration Can then make server-side API calls Use the JS login if you can Redirects are disruptive Requires server-server communication
PERMISSIONS Granular permission model 55 different controls over data access User data Feed, likes, checkins Demographic data, email Friends’ data Friends’ demographics, likes, checkins, etc. Cannot get friends of friends Acting for user Publish to feed stories
FACEBOOK APIS Facebook has 2.5 server-side APIs All RESTful with JSON responses Graph API New, fast, shiny, incomplete OAuth authentication Accessible via the browser REST API Supports almost the entire API To be deprecated, someday Fast new OAuth endpoint Slow old custom auth endpoint
API METHODS REST API method names Many but not all also available via Graph API events.invite pages.blockFan fql.query photos.upload, videos.upload ads.createCampaigns status.set admin.setAppProperties Graph API only: https://graph.facebook.com/user_id/checkins https://graph.facebook.com/app_id/insights
FACEBOOK AND RUBY
MAKING IT WORK WITH RUBY Many Facebook libraries for new Graph/REST APIs Koala Mogli MiniFB rest-graph FBGraph For old REST API/custom auth, one clear winner Facebooker
KOALA My goals: lightweight, fast, flexible, tested All results as basic Ruby objects (Hash, Array)* Full support for Facebook platform OAuth, Graph, REST, realtime updates, test users  Typhoeus and Net::HTTP built in Full RSpec coverage Rails 3- and Ruby 1.9.2-compatible * get_connection and search return GraphCollection < Array, which provides pagination support
AUTHENTICATION WITH COOKIES @oauth = Koala::Facebook::OAuth.new(app_id, secret, callback_url) # pass in Rack cookies directly @oauth.get_user_from_cookies(cookies)  # => &quot;2905623&quot; @oauth.get_user_info_from_cookies(cookies)  # => { &quot;session_key&quot;=> ...,  &quot;uid&quot;=>&quot;2905623&quot; ,  &quot;sig&quot;=> ...,  &quot;secret&quot;=>&quot;YeOkUZhI6csLggJ_jFmm2A__&quot;,  &quot;access_token&quot; => ... }
AUTHENTICATION WITH REDIRECTS @oauth = Koala::Facebook::OAuth.new(app_id, secret, callback_url) @oauth.url_for_oauth_code(:permissions => &quot;publish_stream&quot;)  # => url # send your users there, they’ll return with their codes @oauth.get_access_token(code) # => token @oauth.get_access_token_info(code) # => { &quot;expires&quot; => seconds_from_now,  &quot;access_token&quot; => ... }
USING THE GRAPH API @graph = Koala::Facebook::GraphAPI.new(oauth_token) @graph.get_object(&quot;koppel&quot;)  # => { &quot; name &quot;=>&quot;Alex Koppel&quot;,  &quot; timezone &quot;=>1,  &quot; gender &quot;=>&quot;male&quot;,  &quot; id &quot;=>&quot;2905623&quot;,  &quot; first_name &quot;=>&quot;Alex&quot;, &quot; last_name &quot;=>&quot;Koppel&quot;,  &quot; updated_time &quot;=>&quot;2009-10-25T21:27:40+0000&quot;,  &quot; verified &quot;=>true,  &quot; locale &quot;=>&quot;de_DE&quot;,  &quot; link &quot;=>&quot;http://www.facebook.com/koppel&quot; }
USING THE GRAPH API  @graph.get_connections(&quot;koppel&quot;, &quot;feed&quot;)  # => [{  # lots of data! &quot; id &quot;=>&quot;2905623_174424332576660&quot;,  &quot; message &quot;=>&quot;At Can-Tine drinking beer, eating spicy poutine, and watching Army of Darkness.&quot;,  &quot; likes &quot;=>2, &quot; comments &quot;=>{&quot;data&quot;=>[{&quot;from&quot;=>{&quot;name&quot;=>&quot;Isaac Wolkerstorfer&quot;, &quot;id&quot;=>&quot;2900100&quot;}, &quot;id&quot;=>&quot;2905623_174424332576660_2109285&quot;, &quot;created_time&quot;=>&quot;2010-12-01T20:31:44+0000&quot;, &quot;message&quot;=>&quot;This place sounds amazing.&quot;}], &quot;count&quot;=>1} &quot; from &quot;=>{&quot;name&quot;=>&quot;Alex Koppel&quot;, &quot;id&quot;=>&quot;2905623&quot;}, &quot; created_time &quot;=>&quot;2010-12-01T18:05:09+0000&quot;,  &quot; type &quot;=>&quot;status&quot;,  “ privacy &quot;=>{&quot;value&quot;=>&quot;NETWORKS_FRIENDS&quot;},  &quot; attribution &quot;=>&quot;iPhone&quot;, &quot; actions &quot;=>[{&quot;name&quot;=>&quot;Comment&quot;, &quot;link&quot;=>...}, ...],  }, ...]
USING THE GRAPH API  @graph.search(&quot;Muenchen&quot;)  # => [{  # lots of data! {&quot; from &quot;=>{&quot;name&quot;=>&quot;Daniel Ragogna&quot;, &quot;id&quot;=>&quot;100000110972279&quot;}, &quot; type &quot; => &quot;status&quot;, &quot; message &quot;=>&quot;Muenchen + Dom Rep. Wir kommen Juhu&quot;, &quot; id &quot;=>&quot;100000110972279_160648203978214&quot;},  {&quot; from &quot;=>{&quot;name&quot;=>&quot;Scheinen Saint Jesus Jong&quot;, &quot;id&quot;=>&quot;561597582&quot;}, &quot; type &quot; => &quot;status&quot;, &quot; message &quot;=>&quot;muenchen i m comming&quot;, &quot;id &quot; =>&quot;561597582_171405789546392&quot;},  {&quot; name &quot;=>&quot;Main Concept - Muenchen 58&quot;, &quot; from &quot;=>{&quot;name&quot;=>&quot;Sergej Galkin&quot;, &quot;id&quot;=>&quot;100001607331988&quot;}, &quot; id &quot;=>&quot;100001607331988_154183774628283&quot;, &quot; type &quot;=>&quot;video&quot;,  &quot; source &quot;=>&quot;http://www.youtube.com/v/tyXYK-CgBQo&autoplay=1&quot;, &quot; message &quot;=>&quot;...das Spiel Das Ich Treib...&quot;}, ...]
USING THE GRAPH API @graph.put_wall_post(&quot; hey, i'm learning koala &quot;) # => {&quot;id&quot;=> new_post_id) @graph.put_comment(new_post_id, comment_text)  # => {&quot;id&quot;=> new_comment_id} @graph.delete_object(new_comment_id) # => true
INTEGRATING KOALA Easy to integrate Koala into Rails Create a before_filter for OAuth validation GraphCollections provide pagination params for urls Documentation on github wiki Can also integrate into authentication middleware Devise, OmniAuth, etc.
JAVASCRIPT SDK (FORMERLY FACEBOOK CONNECT)
JAVASCRIPT SDK OVERVIEW Evented Javascript library for Facebook interaction Login and permission management Cookie session storage XFBML Like and login/logout buttons, profile pics and names Asynchronous API access Avoid server load/delays when generating your UI
JAVASCRIPT SDK EXAMPLES Login with permissions FB.login(callback, {perms: permList}) FB.Event.subscribe(&quot;auth.statusChange&quot;, callback); function callback(response) { if (response.session) { // user successfully logged in } else {   // user cancelled login } }; XFBML login button: <fb:login-button perms=“read_stream&quot;></fb:login-button>
JAVASCRIPT SDK EXAMPLES Is the user a fan of your Page? FB.api({method: &quot;pages.isFan”, page_id: pid}, callback); // can show/hide UI elements based on the result Friend list FB.api({method: ”friends.get”}, callback); // build the UI based on the response
WRAPUP
RESOURCES Facebook Developer Wiki Graph API Javascript SDK REST API Facebook Developer Policies Facebook’s Best Practices Facebook’s Bugzilla Koala Facebook library OAuth Playground
ME http://facebook.com/koppel   https://graph.facebook.com/koppel   http://twitter.com/arsduo http://github.com/arsduo http://blog.twoalex.com
EXTRAS
APPENDIX: GRAPH API IN THE BROWSER! You can play with the Graph API in any browser https://graph.facebook.com/ID/CONNECTION_TYPE https://graph.facebook.com/koppel https://graph.facebook.com/contextoptional/feed Private info requires access_token parameter Returns JSON to your browser Go to  http://graph.facebook.com/  to authenticate Links with your OAuth token are halfway down Introduction Add metadata=1 to object URLs to see available options Great way to explore the graph
APPENDIX: PUT_WALL_POST In general, don’t post stories via the API Policy limits what you can post automatically Can’t include user message Browser prompt is a much better experience API use appropriate for offline/mobile experiences

More Related Content

PPT
What's New on the Facebook Platform, May 2011
PDF
Copycat Site BluePrint - make money online fast
PPT
Everything You Need to Know About Being a Sex Blogger (But Were Afraid to Ask)
PDF
Top 10 SharePoint Terms and Acronyms Explained
PDF
THE ULTIMATE BLACKHAT CASH MACHINE - make money online
PPTX
Jetpack All The Things
KEY
OAuth Introduction
PDF
How to use a SharePoint Team Site effectively for Collaboration
What's New on the Facebook Platform, May 2011
Copycat Site BluePrint - make money online fast
Everything You Need to Know About Being a Sex Blogger (But Were Afraid to Ask)
Top 10 SharePoint Terms and Acronyms Explained
THE ULTIMATE BLACKHAT CASH MACHINE - make money online
Jetpack All The Things
OAuth Introduction
How to use a SharePoint Team Site effectively for Collaboration

What's hot (20)

PPTX
SharePoint Training
PDF
Facebook Black book 3 - make money online everyday
PDF
Do Follow Backlinks Packet Free of Cost Download Here
PDF
Kick-Ass Project Collaboration with Office 365 Groups
PDF
STOP HACKERS & THIEVES
PPTX
Sharepoint tips and tricks
PDF
Introduction to Facebook JavaScript & Python SDK
DOCX
Posterous Guide: The Easy Way to Blog
PDF
Get Top
PDF
How to Fix Error 404 in Wordpress
PDF
SharePoint Out of the Box
PPT
ONA08 - Jesse Thomas
PDF
How to fix error 404 not found on word press
PDF
SharePoint Tips and Tricks you cannot live without
PDF
Don't Suck at SharePoint - Avoid the common mistakes
PDF
Pr7 8 clubwear-and-party-wear
PDF
Facebook Open Graph Tech Requirements
PDF
SharePoint External Sharing
PDF
Wireframing recitation
PDF
Free SEO
SharePoint Training
Facebook Black book 3 - make money online everyday
Do Follow Backlinks Packet Free of Cost Download Here
Kick-Ass Project Collaboration with Office 365 Groups
STOP HACKERS & THIEVES
Sharepoint tips and tricks
Introduction to Facebook JavaScript & Python SDK
Posterous Guide: The Easy Way to Blog
Get Top
How to Fix Error 404 in Wordpress
SharePoint Out of the Box
ONA08 - Jesse Thomas
How to fix error 404 not found on word press
SharePoint Tips and Tricks you cannot live without
Don't Suck at SharePoint - Avoid the common mistakes
Pr7 8 clubwear-and-party-wear
Facebook Open Graph Tech Requirements
SharePoint External Sharing
Wireframing recitation
Free SEO
Ad

Viewers also liked (20)

PPT
Impacts of Predation on Mule Deer in Utah, April 2011
PPT
Happy facebook developer
PDF
Making Facebook Faster
PDF
Facebook App Development
PPT
Facebook Development with Zend Framework
PDF
Introduction to Facebook Javascript SDK (NEW)
PDF
Workshop : Facebook JavaScript SDK
PDF
Introduction to facebook java script sdk
PDF
Introduction to facebook javascript sdk
PPT
2011 CWMU antlerless permit review and recommendations, May 4, 2011
PDF
Chelsea Property Group (Reit)
PDF
Mobile CRM Webinar: 6 Must Haves For Effective Cross Channel CRM
PDF
Hotel in Deer Park Texas
PDF
Using smtp over_bgan_en
PDF
Mobile's Data Game: How to Play by the Rules and Win
PPTX
Phoenix Sales Conference
PDF
שיעורי בית בפסיכומטרי
KEY
When it rains: Prepare for scale with Amazon EC2
PPTX
Prezentacja tz3 promocja_blog
PDF
In 10 Stappen Een Hypotheek
Impacts of Predation on Mule Deer in Utah, April 2011
Happy facebook developer
Making Facebook Faster
Facebook App Development
Facebook Development with Zend Framework
Introduction to Facebook Javascript SDK (NEW)
Workshop : Facebook JavaScript SDK
Introduction to facebook java script sdk
Introduction to facebook javascript sdk
2011 CWMU antlerless permit review and recommendations, May 4, 2011
Chelsea Property Group (Reit)
Mobile CRM Webinar: 6 Must Haves For Effective Cross Channel CRM
Hotel in Deer Park Texas
Using smtp over_bgan_en
Mobile's Data Game: How to Play by the Rules and Win
Phoenix Sales Conference
שיעורי בית בפסיכומטרי
When it rains: Prepare for scale with Amazon EC2
Prezentacja tz3 promocja_blog
In 10 Stappen Een Hypotheek
Ad

Similar to Facebook + Ruby (20)

PPTX
Facebook Apps Development 101 (Java)
ODP
Facebook Platform
PPT
What's New on the Facebook Platform, July 2011
PPTX
Shiny Agency's Facebook Development Guidelines
PPSX
AIR & API
PPT
Facebook api
PPT
Facebook API
PDF
Leveraging Rails to Build Facebook Apps
PPT
Hi5 Open Social
PPT
Facebook Coin
ODP
Facebook Social Plugins
PDF
Social Apps with the Force.com Toolkit for Facebook
PDF
APIdays Helsinki 2019 - API Versioning with REST, JSON and Swagger with Thoma...
PPT
OpenSocial Intro
PPTX
The Flash Facebook Cookbook - FlashMidlands
PPT
Facebook Connect Integration
PPT
Getting the Most Out of OpenSocial Gadgets
PPTX
Designing CakePHP plugins for consuming APIs
PPTX
Creating a content managed facebook app
PPT
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines
Facebook Apps Development 101 (Java)
Facebook Platform
What's New on the Facebook Platform, July 2011
Shiny Agency's Facebook Development Guidelines
AIR & API
Facebook api
Facebook API
Leveraging Rails to Build Facebook Apps
Hi5 Open Social
Facebook Coin
Facebook Social Plugins
Social Apps with the Force.com Toolkit for Facebook
APIdays Helsinki 2019 - API Versioning with REST, JSON and Swagger with Thoma...
OpenSocial Intro
The Flash Facebook Cookbook - FlashMidlands
Facebook Connect Integration
Getting the Most Out of OpenSocial Gadgets
Designing CakePHP plugins for consuming APIs
Creating a content managed facebook app
JBUG 11 - Django-The Web Framework For Perfectionists With Deadlines

Recently uploaded (20)

PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
DP Operators-handbook-extract for the Mautical Institute
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
A Presentation on Touch Screen Technology
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
A novel scalable deep ensemble learning framework for big data classification...
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
WOOl fibre morphology and structure.pdf for textiles
SOPHOS-XG Firewall Administrator PPT.pptx
DP Operators-handbook-extract for the Mautical Institute
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Heart disease approach using modified random forest and particle swarm optimi...
Digital-Transformation-Roadmap-for-Companies.pptx
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
cloud_computing_Infrastucture_as_cloud_p
1 - Historical Antecedents, Social Consideration.pdf
Approach and Philosophy of On baking technology
OMC Textile Division Presentation 2021.pptx
Programs and apps: productivity, graphics, security and other tools
A Presentation on Touch Screen Technology
Unlocking AI with Model Context Protocol (MCP)
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Getting Started with Data Integration: FME Form 101
Enhancing emotion recognition model for a student engagement use case through...
A novel scalable deep ensemble learning framework for big data classification...

Facebook + Ruby

  • 1. + Building Facebook Applications with Ruby Alex Koppel, 12/2010
  • 2. WHY DEVELOP WITH FACEBOOK? Over 500 million users 50% of active users log on every day 150 million in USA 10 million in Germany Application Platform Over 550,000 applications Over 1,000,000 websites integrated with Facebook Over 150 million users use such FB integrations / month Huge audience, extensive Platform
  • 3. WHAT CAN APPS OFFER USERS? Better interface to Facebook core functionality iPhoto, Wall moderation and publishing platforms Promotion of an existing service Netflix, Yelp, Goodreads Create a connection with fans of a brand Chase Community Giving, other branded apps Authentication Groupon, Kayak, Goodreads Many applications fall into multiple categories
  • 4. WHAT KINDS OF APPS ARE THERE? Websites Your own site Complete control Javascript SDK Any level of integration Canvas Apps Tab Apps Mobile Apps Desktop Apps Hosted on facebook.com Less friction for users on the site Some limitations (size/etc.) FBML+FBJS => restrictions
  • 5. WEBSITES Wherever, whatever Benefits for users A way to share activity Easy login Lightweight integration Social plugins (iframes) Javascript SDK only Heavyweight integration Javascript frontend Server backend
  • 6. CANVAS APPS Live on Facebook iframe or FBML iframe ~ website FBML to be retired Less friction than off-FB apps Users stay on site Have to work within Facebook limits iframe container Fixed size
  • 7. TAB APPS Live on Facebook Page Tight integration with Page (brand/product) Can help drive Liking Limitations FBML/FBJS only (iframe in the future) Size limitation First load is anonymous
  • 8. FACEBOOK INTEGRATION Both front- and back-end integration Browser handles tasks requiring interaction Login, permissions, publishing stories Server handles many API-related tasks Offline access, realtime updates, app management Persisting results Many tasks can be done by either server or client Authentication API calls Let your need guide you
  • 10. FACEBOOK AUTHENTICATION OAuth-based authentication scheme Token provides access to user info Multiple ways to authenticate Javascript API Redirect with OAuth code Signed request parameters Provided in request to tab and canvas apps Old proprietary auth scheme being deprecated
  • 11. AUTHENTICATING WITH JAVASCRIPT iframe-based secure login prompt XFBML login button Programatic via Javascript Includes permissions if desired Browser gets OAuth token, user ID, expiration, etc. Notified through callback and event Javascript sets signed cookie cookies Server libraries provided parsing Preferred method Easy for users Keeps people on your site
  • 12. AUTHENTICATING WITH REDIRECTS Send user to login page on facebook.com User redirected to app’s callback with OAuth code App server requests token using code and secret Server gets OAuth token and expiration Can then make server-side API calls Use the JS login if you can Redirects are disruptive Requires server-server communication
  • 13. PERMISSIONS Granular permission model 55 different controls over data access User data Feed, likes, checkins Demographic data, email Friends’ data Friends’ demographics, likes, checkins, etc. Cannot get friends of friends Acting for user Publish to feed stories
  • 14. FACEBOOK APIS Facebook has 2.5 server-side APIs All RESTful with JSON responses Graph API New, fast, shiny, incomplete OAuth authentication Accessible via the browser REST API Supports almost the entire API To be deprecated, someday Fast new OAuth endpoint Slow old custom auth endpoint
  • 15. API METHODS REST API method names Many but not all also available via Graph API events.invite pages.blockFan fql.query photos.upload, videos.upload ads.createCampaigns status.set admin.setAppProperties Graph API only: https://graph.facebook.com/user_id/checkins https://graph.facebook.com/app_id/insights
  • 17. MAKING IT WORK WITH RUBY Many Facebook libraries for new Graph/REST APIs Koala Mogli MiniFB rest-graph FBGraph For old REST API/custom auth, one clear winner Facebooker
  • 18. KOALA My goals: lightweight, fast, flexible, tested All results as basic Ruby objects (Hash, Array)* Full support for Facebook platform OAuth, Graph, REST, realtime updates, test users Typhoeus and Net::HTTP built in Full RSpec coverage Rails 3- and Ruby 1.9.2-compatible * get_connection and search return GraphCollection < Array, which provides pagination support
  • 19. AUTHENTICATION WITH COOKIES @oauth = Koala::Facebook::OAuth.new(app_id, secret, callback_url) # pass in Rack cookies directly @oauth.get_user_from_cookies(cookies) # => &quot;2905623&quot; @oauth.get_user_info_from_cookies(cookies) # => { &quot;session_key&quot;=> ..., &quot;uid&quot;=>&quot;2905623&quot; , &quot;sig&quot;=> ..., &quot;secret&quot;=>&quot;YeOkUZhI6csLggJ_jFmm2A__&quot;, &quot;access_token&quot; => ... }
  • 20. AUTHENTICATION WITH REDIRECTS @oauth = Koala::Facebook::OAuth.new(app_id, secret, callback_url) @oauth.url_for_oauth_code(:permissions => &quot;publish_stream&quot;) # => url # send your users there, they’ll return with their codes @oauth.get_access_token(code) # => token @oauth.get_access_token_info(code) # => { &quot;expires&quot; => seconds_from_now, &quot;access_token&quot; => ... }
  • 21. USING THE GRAPH API @graph = Koala::Facebook::GraphAPI.new(oauth_token) @graph.get_object(&quot;koppel&quot;) # => { &quot; name &quot;=>&quot;Alex Koppel&quot;, &quot; timezone &quot;=>1, &quot; gender &quot;=>&quot;male&quot;, &quot; id &quot;=>&quot;2905623&quot;, &quot; first_name &quot;=>&quot;Alex&quot;, &quot; last_name &quot;=>&quot;Koppel&quot;, &quot; updated_time &quot;=>&quot;2009-10-25T21:27:40+0000&quot;, &quot; verified &quot;=>true, &quot; locale &quot;=>&quot;de_DE&quot;, &quot; link &quot;=>&quot;http://www.facebook.com/koppel&quot; }
  • 22. USING THE GRAPH API @graph.get_connections(&quot;koppel&quot;, &quot;feed&quot;) # => [{ # lots of data! &quot; id &quot;=>&quot;2905623_174424332576660&quot;, &quot; message &quot;=>&quot;At Can-Tine drinking beer, eating spicy poutine, and watching Army of Darkness.&quot;, &quot; likes &quot;=>2, &quot; comments &quot;=>{&quot;data&quot;=>[{&quot;from&quot;=>{&quot;name&quot;=>&quot;Isaac Wolkerstorfer&quot;, &quot;id&quot;=>&quot;2900100&quot;}, &quot;id&quot;=>&quot;2905623_174424332576660_2109285&quot;, &quot;created_time&quot;=>&quot;2010-12-01T20:31:44+0000&quot;, &quot;message&quot;=>&quot;This place sounds amazing.&quot;}], &quot;count&quot;=>1} &quot; from &quot;=>{&quot;name&quot;=>&quot;Alex Koppel&quot;, &quot;id&quot;=>&quot;2905623&quot;}, &quot; created_time &quot;=>&quot;2010-12-01T18:05:09+0000&quot;, &quot; type &quot;=>&quot;status&quot;, “ privacy &quot;=>{&quot;value&quot;=>&quot;NETWORKS_FRIENDS&quot;}, &quot; attribution &quot;=>&quot;iPhone&quot;, &quot; actions &quot;=>[{&quot;name&quot;=>&quot;Comment&quot;, &quot;link&quot;=>...}, ...], }, ...]
  • 23. USING THE GRAPH API @graph.search(&quot;Muenchen&quot;) # => [{ # lots of data! {&quot; from &quot;=>{&quot;name&quot;=>&quot;Daniel Ragogna&quot;, &quot;id&quot;=>&quot;100000110972279&quot;}, &quot; type &quot; => &quot;status&quot;, &quot; message &quot;=>&quot;Muenchen + Dom Rep. Wir kommen Juhu&quot;, &quot; id &quot;=>&quot;100000110972279_160648203978214&quot;}, {&quot; from &quot;=>{&quot;name&quot;=>&quot;Scheinen Saint Jesus Jong&quot;, &quot;id&quot;=>&quot;561597582&quot;}, &quot; type &quot; => &quot;status&quot;, &quot; message &quot;=>&quot;muenchen i m comming&quot;, &quot;id &quot; =>&quot;561597582_171405789546392&quot;}, {&quot; name &quot;=>&quot;Main Concept - Muenchen 58&quot;, &quot; from &quot;=>{&quot;name&quot;=>&quot;Sergej Galkin&quot;, &quot;id&quot;=>&quot;100001607331988&quot;}, &quot; id &quot;=>&quot;100001607331988_154183774628283&quot;, &quot; type &quot;=>&quot;video&quot;, &quot; source &quot;=>&quot;http://www.youtube.com/v/tyXYK-CgBQo&autoplay=1&quot;, &quot; message &quot;=>&quot;...das Spiel Das Ich Treib...&quot;}, ...]
  • 24. USING THE GRAPH API @graph.put_wall_post(&quot; hey, i'm learning koala &quot;) # => {&quot;id&quot;=> new_post_id) @graph.put_comment(new_post_id, comment_text) # => {&quot;id&quot;=> new_comment_id} @graph.delete_object(new_comment_id) # => true
  • 25. INTEGRATING KOALA Easy to integrate Koala into Rails Create a before_filter for OAuth validation GraphCollections provide pagination params for urls Documentation on github wiki Can also integrate into authentication middleware Devise, OmniAuth, etc.
  • 26. JAVASCRIPT SDK (FORMERLY FACEBOOK CONNECT)
  • 27. JAVASCRIPT SDK OVERVIEW Evented Javascript library for Facebook interaction Login and permission management Cookie session storage XFBML Like and login/logout buttons, profile pics and names Asynchronous API access Avoid server load/delays when generating your UI
  • 28. JAVASCRIPT SDK EXAMPLES Login with permissions FB.login(callback, {perms: permList}) FB.Event.subscribe(&quot;auth.statusChange&quot;, callback); function callback(response) { if (response.session) { // user successfully logged in } else { // user cancelled login } }; XFBML login button: <fb:login-button perms=“read_stream&quot;></fb:login-button>
  • 29. JAVASCRIPT SDK EXAMPLES Is the user a fan of your Page? FB.api({method: &quot;pages.isFan”, page_id: pid}, callback); // can show/hide UI elements based on the result Friend list FB.api({method: ”friends.get”}, callback); // build the UI based on the response
  • 31. RESOURCES Facebook Developer Wiki Graph API Javascript SDK REST API Facebook Developer Policies Facebook’s Best Practices Facebook’s Bugzilla Koala Facebook library OAuth Playground
  • 32. ME http://facebook.com/koppel https://graph.facebook.com/koppel http://twitter.com/arsduo http://github.com/arsduo http://blog.twoalex.com
  • 34. APPENDIX: GRAPH API IN THE BROWSER! You can play with the Graph API in any browser https://graph.facebook.com/ID/CONNECTION_TYPE https://graph.facebook.com/koppel https://graph.facebook.com/contextoptional/feed Private info requires access_token parameter Returns JSON to your browser Go to http://graph.facebook.com/ to authenticate Links with your OAuth token are halfway down Introduction Add metadata=1 to object URLs to see available options Great way to explore the graph
  • 35. APPENDIX: PUT_WALL_POST In general, don’t post stories via the API Policy limits what you can post automatically Can’t include user message Browser prompt is a much better experience API use appropriate for offline/mobile experiences