SlideShare a Scribd company logo
Facebook Apps Dev 101Damon Widjaja
Facebook Apps BasicIntegrate web applications with core Facebook ExperienceExample: getting user information and posting to wallBenefit? A powerful and cost effective measures for one's product/service to gain exposure (i.e. user engagement, viral effect)
Getting StartedStep 1: Registering applicationStep 2: Setting-up applicationStep 3: Authorizing applicationStep 4: Accessing user informationStep 5: Interacting with Facebook
Step 1: Registering ApplicationAdd Facebook develop apps @ http://www.facebook.com/developersVerify Facebook account (Mobile phone or credit card)Create your application!Get a unique application ID and secret
Here we gosource: http://developers.facebook.com/docs/guides/canvas/
CanvasA blank window within Facebook on which to run your applicationMinimum screen size of only 760 px wideType of Canvas:iFrameFBML
Tiny screensource: http://developers.facebook.com/docs/guides/canvas/
iFramevs FBMLiFrame Benefits:Scalability in the long run (i.e. easy to move to Facebook Connect website)Let you use Javascript, HTML, CSS (Ajax anyone?)Easy to debugFBML Benefits:Easy to access Facebook elementsFaster loadsNote: FBML might be deprecated
Step 2: Setting-up Application - CanvasSet your canvas name (Very important!)Easy to rememberBranding perspectiveExample: http://www.facebook.com/myappSet your canvas URLOpens in canvasExample: http://www.myapp.com
Hello world!http://www.myapp.com
Coding time!Development environment assumptionJavaStruts2TomcatmySqlMost tutorials and examples on the web is in PHP
Step 3: Authorizing applicationIs it required? No!BUT it is necessary to create a personalized user experience (i.e. retrieve user email address, post to wall)App creator controls the degree of permissions required during authorization
Tell me how?Call the following URI on your default index page upon loadhttps://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URLOr, append specific scope parametershttps://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=email,read_stream
Add this applicationsource: http://developers.facebook.com/docs/authentication/
Sample code - Part 1<script type="text/javascript"><!--<%String uri = "http://apps.facebook.com/myapp/login";String appId = "12345678910";String perms = "email,user_birthday"; String url = "https://graph.facebook.com/oauth/authorize?scope="+perms+"&client_id=" + appId; 
Sample code - Part 2if (uri != null) {     try {          uri = java.net.URLEncoder.encode(uri, "UTF-8");     }     catch (java.io.UnsupportedEncodingException e) {     }} url = url + "&redirect_uri=" + uri;out.println("varurl=\""+url+"\";");%> if(url != null) {   window.open(url, "_parent", "");}--></script>
What’s next?Have to know fact! Facebook passes user information in the form of signed_requestparameter to the canvas URL This signed_requestparameter is a base64url encoded JSON objectHuh? Simply saying, signed_requesthas to be decoded to be meaningful!
Super Secretsource: http://developers.facebook.com/docs/authentication/signed_request/
Why bother?Within the encoded signed_requestparameter, lies the very important access_tokenCool, so what is it for? access_tokenis necessary to gain access to private information granted during authorizationAnd oh, Facebook defines the steps to decode signed_request
Facebook sayssource: http://developers.facebook.com/docs/authentication/signed_request/
Sample code -  Part 1String accessToken = null;String signedRequest = request.getParameter("signed_request");if (signedRequest == null || signedRequest.length() == 0) {     log.error("AUTH ERROR: Facebook signed request is missing");     return"ERROR";}int count = 0;String payload = null;
Sample code -  Part 2//Break the code using tokenizerStringTokenizerst = new StringTokenizer(signedRequest, ".");while (st.hasMoreTokens()){     if(count == 1)     {          payload = st.nextToken();          break;     }     else          st.nextToken();     count++;}
Sample code -  Part 3//Decode Base64BASE64Decoder decoder = new BASE64Decoder();//Replace spepayload = payload.replace("-", "+").replace("_", "/").trim();//Decode Base64 - payloadtry {     byte[] decodedPayload = decoder.decodeBuffer(payload);     payload = new String(decodedPayload, "UTF8");} catch (IOException e) {     // TODO Auto-generated catch block     log.error("ERROR: Unable to perform Base64 Decode");     return null;}
Sample code -  Part 4//JSON Decode - payloadtry {     JSONObjectpayloadObject = new JSONObject(payload);     //Parse JSON data     accessToken = "" + payloadObject.get("oauth_token"); //Retrieve oauth token} catch (JSONException e) {     log.error("ERROR: Unable to perform JSON decode");}
Step 4: Accessing user informationThe simplicity of Graph APIREST standard, returns data in JSON formatTry the followinghttp://graph.facebook.com/mehttp://graph.facebook.com/me/picture
Utilizing access tokenMost still returns information without access tokenBUT Data is limited to public informationTry the following with access tokenhttp://graph.facebook.com/me?access_token=WHILE Some strictly requires access tokenhttps://graph.facebook.com/me/friends?access_token=
The Java WayEasy way to execute Graph API requestGeneric functions supportedGet the API from http://code.google.com/p/facebook-java-api/
Sample codeFacebookClientfacebookClient = new DefaultFacebookClient(accessToken);JsonObjectfbUserJSON = facebookClient.fetchObject("me", JsonObject.class);String facebookId = fbUserJSON.getString("id");String firstName = fbUserJSON.getString("first_name");
Step 5: Interacting with FacebookAccessing popular Facebook featuresClient-side scripting using Javascript SDKExtensive functionalities: From making Graph API calls to opening Popular Dialogs
Popular DialogsJavascriptfunction to trigger commonly used Facebook dialogsPost to wallInvite friendsPermission requested during authentication applies here!
The familiar pop-up!source: http://developers.facebook.com/docs/reference/dialogs/
Sample code - Part 1<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, // check login status    cookie : false, // enable cookies to allow the server to access the session    xfbml  : true  // parse XFBML  }); </script>
Sample code - Part 2function postToWall() {     FB.ui({            method: 'feed',            name: ‘FacebookDialogs',            link: 'http://my-app.com',            caption: ’Reference Documentation',            description: ’Dialogsprovide simple, consistent interface…',            message: ’Facebook dialogs are soeasy'     }, function(response) {            if (response && response.post_id) {                alert('Successful!');            } else {                alert('Uh-oh, something is wrong.');            }     });     return false;}
Congrats!You are now a full-fledge Facebook Apps Developer!Why don’t challenge yourself to do the following:Create a simple Facebook application that incorporates what we have learnt in this sessionImpress your teacher!Claim it at http://www.gamemaki.com

More Related Content

PDF
Facebook Open Graph Tech Requirements
PDF
Leveraging Rails to Build Facebook Apps
PPTX
Facebook and its development
PPT
Facebook api
PPTX
Shiny Agency's Facebook Development Guidelines
PPTX
SEO and Social Media for Multilingual and Multidevice Sites
PDF
Microsoft Word Facebook And Twitter Advanced Class Links
PDF
THE ULTIMATE BLACKHAT CASH MACHINE - make money online
Facebook Open Graph Tech Requirements
Leveraging Rails to Build Facebook Apps
Facebook and its development
Facebook api
Shiny Agency's Facebook Development Guidelines
SEO and Social Media for Multilingual and Multidevice Sites
Microsoft Word Facebook And Twitter Advanced Class Links
THE ULTIMATE BLACKHAT CASH MACHINE - make money online

What's hot (20)

KEY
Graph API - Facebook Developer Garage Taipei
PDF
Android app development guide for freshers by ace web academy
PDF
Introduction to Facebook Graph API and OAuth 2
PDF
Facebook graph api
ODP
Web Application Lunacy
PPT
Info2006 Web20 Taly Print
PDF
Pr7 8 clubwear-and-party-wear
PDF
Introduction to Facebook Javascript SDK (NEW)
PDF
Workshop : Facebook JavaScript SDK
PPTX
Introduction to HTML5 & CSS3
PPT
Pinned Sites in Internet Explorer 9
DOC
Done rerea dspamguide2003
PDF
Passport js authentication in nodejs how to implement facebook login feature ...
PDF
Penguin recovery penalty
PDF
How to create Zoom Meet with Pega
PDF
Facebook API for iOS
PPTX
Building Viral Social Experiences
PPT
Web Spam Techniques
PDF
Vdomainhosting wordpress-seo-checklist20151016e
PDF
Facebook API for Developers : Introducing the Facebook Platform
Graph API - Facebook Developer Garage Taipei
Android app development guide for freshers by ace web academy
Introduction to Facebook Graph API and OAuth 2
Facebook graph api
Web Application Lunacy
Info2006 Web20 Taly Print
Pr7 8 clubwear-and-party-wear
Introduction to Facebook Javascript SDK (NEW)
Workshop : Facebook JavaScript SDK
Introduction to HTML5 & CSS3
Pinned Sites in Internet Explorer 9
Done rerea dspamguide2003
Passport js authentication in nodejs how to implement facebook login feature ...
Penguin recovery penalty
How to create Zoom Meet with Pega
Facebook API for iOS
Building Viral Social Experiences
Web Spam Techniques
Vdomainhosting wordpress-seo-checklist20151016e
Facebook API for Developers : Introducing the Facebook Platform
Ad

Similar to Facebook Apps Development 101 (Java) (20)

PDF
Charlie Cheever Facebook Developer Garage Uganda
PPT
Happy facebook developer
ODP
Facebook Platform
KEY
OAuth Introduction
PPT
What's New on the Facebook Platform, May 2011
PDF
Building Facebook Apps
PPT
Creating a Facebook App
PPTX
The Flash Facebook Cookbook - FlashMidlands
PPT
What's New on the Facebook Platform, July 2011
PDF
Build social apps for Facebook
PPT
Facebook + Ruby
PPTX
Facebook Developer Garage Cyberjaya
KEY
페이스북 소셜 앱 개발 가이드 2011
PDF
funP 麻吉 開發者俱樂部十月份聚會
PPT
Facebook 3rd Party Api
PPTX
Get Social With Facebook
PPT
Facebook API
PDF
Developing Facebook Application
PPT
Facebook Apps
Charlie Cheever Facebook Developer Garage Uganda
Happy facebook developer
Facebook Platform
OAuth Introduction
What's New on the Facebook Platform, May 2011
Building Facebook Apps
Creating a Facebook App
The Flash Facebook Cookbook - FlashMidlands
What's New on the Facebook Platform, July 2011
Build social apps for Facebook
Facebook + Ruby
Facebook Developer Garage Cyberjaya
페이스북 소셜 앱 개발 가이드 2011
funP 麻吉 開發者俱樂部十月份聚會
Facebook 3rd Party Api
Get Social With Facebook
Facebook API
Developing Facebook Application
Facebook Apps
Ad

Recently uploaded (20)

PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPT
Teaching material agriculture food technology
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Encapsulation_ Review paper, used for researhc scholars
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Approach and Philosophy of On baking technology
PPTX
Cloud computing and distributed systems.
PDF
Empathic Computing: Creating Shared Understanding
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
Chapter 3 Spatial Domain Image Processing.pdf
Teaching material agriculture food technology
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
The AUB Centre for AI in Media Proposal.docx
Mobile App Security Testing_ A Comprehensive Guide.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Encapsulation_ Review paper, used for researhc scholars
Understanding_Digital_Forensics_Presentation.pptx
Dropbox Q2 2025 Financial Results & Investor Presentation
Review of recent advances in non-invasive hemoglobin estimation
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Approach and Philosophy of On baking technology
Cloud computing and distributed systems.
Empathic Computing: Creating Shared Understanding
Programs and apps: productivity, graphics, security and other tools
The Rise and Fall of 3GPP – Time for a Sabbatical?

Facebook Apps Development 101 (Java)

  • 1. Facebook Apps Dev 101Damon Widjaja
  • 2. Facebook Apps BasicIntegrate web applications with core Facebook ExperienceExample: getting user information and posting to wallBenefit? A powerful and cost effective measures for one's product/service to gain exposure (i.e. user engagement, viral effect)
  • 3. Getting StartedStep 1: Registering applicationStep 2: Setting-up applicationStep 3: Authorizing applicationStep 4: Accessing user informationStep 5: Interacting with Facebook
  • 4. Step 1: Registering ApplicationAdd Facebook develop apps @ http://www.facebook.com/developersVerify Facebook account (Mobile phone or credit card)Create your application!Get a unique application ID and secret
  • 5. Here we gosource: http://developers.facebook.com/docs/guides/canvas/
  • 6. CanvasA blank window within Facebook on which to run your applicationMinimum screen size of only 760 px wideType of Canvas:iFrameFBML
  • 8. iFramevs FBMLiFrame Benefits:Scalability in the long run (i.e. easy to move to Facebook Connect website)Let you use Javascript, HTML, CSS (Ajax anyone?)Easy to debugFBML Benefits:Easy to access Facebook elementsFaster loadsNote: FBML might be deprecated
  • 9. Step 2: Setting-up Application - CanvasSet your canvas name (Very important!)Easy to rememberBranding perspectiveExample: http://www.facebook.com/myappSet your canvas URLOpens in canvasExample: http://www.myapp.com
  • 11. Coding time!Development environment assumptionJavaStruts2TomcatmySqlMost tutorials and examples on the web is in PHP
  • 12. Step 3: Authorizing applicationIs it required? No!BUT it is necessary to create a personalized user experience (i.e. retrieve user email address, post to wall)App creator controls the degree of permissions required during authorization
  • 13. Tell me how?Call the following URI on your default index page upon loadhttps://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URLOr, append specific scope parametershttps://www.facebook.com/dialog/oauth?client_id=YOUR_APP_ID&redirect_uri=YOUR_URL&scope=email,read_stream
  • 14. Add this applicationsource: http://developers.facebook.com/docs/authentication/
  • 15. Sample code - Part 1<script type="text/javascript"><!--<%String uri = "http://apps.facebook.com/myapp/login";String appId = "12345678910";String perms = "email,user_birthday"; String url = "https://graph.facebook.com/oauth/authorize?scope="+perms+"&client_id=" + appId; 
  • 16. Sample code - Part 2if (uri != null) {     try {          uri = java.net.URLEncoder.encode(uri, "UTF-8");     }     catch (java.io.UnsupportedEncodingException e) {     }} url = url + "&redirect_uri=" + uri;out.println("varurl=\""+url+"\";");%> if(url != null) {   window.open(url, "_parent", "");}--></script>
  • 17. What’s next?Have to know fact! Facebook passes user information in the form of signed_requestparameter to the canvas URL This signed_requestparameter is a base64url encoded JSON objectHuh? Simply saying, signed_requesthas to be decoded to be meaningful!
  • 19. Why bother?Within the encoded signed_requestparameter, lies the very important access_tokenCool, so what is it for? access_tokenis necessary to gain access to private information granted during authorizationAnd oh, Facebook defines the steps to decode signed_request
  • 21. Sample code - Part 1String accessToken = null;String signedRequest = request.getParameter("signed_request");if (signedRequest == null || signedRequest.length() == 0) {     log.error("AUTH ERROR: Facebook signed request is missing");     return"ERROR";}int count = 0;String payload = null;
  • 22. Sample code - Part 2//Break the code using tokenizerStringTokenizerst = new StringTokenizer(signedRequest, ".");while (st.hasMoreTokens()){    if(count == 1)     {          payload = st.nextToken();          break;     }     else          st.nextToken();     count++;}
  • 23. Sample code - Part 3//Decode Base64BASE64Decoder decoder = new BASE64Decoder();//Replace spepayload = payload.replace("-", "+").replace("_", "/").trim();//Decode Base64 - payloadtry {     byte[] decodedPayload = decoder.decodeBuffer(payload);     payload = new String(decodedPayload, "UTF8");} catch (IOException e) {     // TODO Auto-generated catch block     log.error("ERROR: Unable to perform Base64 Decode");     return null;}
  • 24. Sample code - Part 4//JSON Decode - payloadtry {     JSONObjectpayloadObject = new JSONObject(payload);     //Parse JSON data     accessToken = "" + payloadObject.get("oauth_token"); //Retrieve oauth token} catch (JSONException e) {     log.error("ERROR: Unable to perform JSON decode");}
  • 25. Step 4: Accessing user informationThe simplicity of Graph APIREST standard, returns data in JSON formatTry the followinghttp://graph.facebook.com/mehttp://graph.facebook.com/me/picture
  • 26. Utilizing access tokenMost still returns information without access tokenBUT Data is limited to public informationTry the following with access tokenhttp://graph.facebook.com/me?access_token=WHILE Some strictly requires access tokenhttps://graph.facebook.com/me/friends?access_token=
  • 27. The Java WayEasy way to execute Graph API requestGeneric functions supportedGet the API from http://code.google.com/p/facebook-java-api/
  • 28. Sample codeFacebookClientfacebookClient = new DefaultFacebookClient(accessToken);JsonObjectfbUserJSON = facebookClient.fetchObject("me", JsonObject.class);String facebookId = fbUserJSON.getString("id");String firstName = fbUserJSON.getString("first_name");
  • 29. Step 5: Interacting with FacebookAccessing popular Facebook featuresClient-side scripting using Javascript SDKExtensive functionalities: From making Graph API calls to opening Popular Dialogs
  • 30. Popular DialogsJavascriptfunction to trigger commonly used Facebook dialogsPost to wallInvite friendsPermission requested during authentication applies here!
  • 31. The familiar pop-up!source: http://developers.facebook.com/docs/reference/dialogs/
  • 32. Sample code - Part 1<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, // check login status    cookie : false, // enable cookies to allow the server to access the session    xfbml  : true  // parse XFBML  }); </script>
  • 33. Sample code - Part 2function postToWall() {     FB.ui({            method: 'feed',            name: ‘FacebookDialogs',            link: 'http://my-app.com',            caption: ’Reference Documentation',            description: ’Dialogsprovide simple, consistent interface…',            message: ’Facebook dialogs are soeasy'     }, function(response) {            if (response && response.post_id) {                alert('Successful!');            } else {                alert('Uh-oh, something is wrong.');            }     });     return false;}
  • 34. Congrats!You are now a full-fledge Facebook Apps Developer!Why don’t challenge yourself to do the following:Create a simple Facebook application that incorporates what we have learnt in this sessionImpress your teacher!Claim it at http://www.gamemaki.com

Editor's Notes

  • #3: Source:http://developers.facebook.com/docs/guides/canvas/http://www.articletrader.com/computers/software/key-benefits-of-facebook-application-development.html
  • #9: Source:http://www.ccheever.com/blog/?p=10
  • #14: Source:http://developers.facebook.com/docs/authentication/http://developers.facebook.com/docs/authentication/permissions/
  • #18: Source:http://developers.facebook.com/docs/authentication/signed_request/
  • #22: Source:http://developers.facebook.com/docs/authentication/signed_request/
  • #23: Source:http://developers.facebook.com/docs/authentication/signed_request/
  • #24: Source:http://developers.facebook.com/docs/authentication/signed_request/
  • #25: Source:http://developers.facebook.com/docs/authentication/signed_request/
  • #26: Source:http://developers.facebook.com/docs/reference/api/
  • #27: Source:http://developers.facebook.com/docs/reference/api/
  • #29: Source:http://developers.facebook.com/docs/authentication/signed_request/
  • #30: Source:http://developers.facebook.com/docs/reference/javascript/