SlideShare une entreprise Scribd logo
1  sur  31
Télécharger pour lire hors ligne
API
Introduction to Facebook Javascript API
Social Network and Applications, 2011
LittleQ, The department of Computer Science, NCCU




                                                    f   Introduction to
                                                        Facebook JS API
Objectives



• Learn the concepts of Facebook API
• Learn how to use Facebook API with
  Javascript


                                f   Introduction to
                                    Facebook JS API
Core Topics

• Facebook Developers website
• Graph API
• Facebook Javascript SDK
• Resources

                                f   Introduction to
                                    Facebook JS API
Facebook Developers

• Provide you online documentations
• Forum for discussion
• Management of your applications


                                f     Introduction to
                                      Facebook JS API
Where is it?




               f   Introduction to
                   Facebook JS API
Social Plugins


• Like Button, Send Button, Login Button
• Comments
• Registration
• Activity Feed, Live Stream
                                      f
                                     Introduction to
                                          Facebook JS API
Graph API
              Response Data               Aggregate Information




              Access Token                    Request Data



Application                   Graph API                      Facebook Database



 • Facebook’s core
 • Social graph
 • Connections
                                                                  f   Introduction to
                                                                      Facebook JS API
Graph Model

• Composed of objects and connections
• Identify entities and relationships by id
• Data will be stored with smallest spaces
  and keep being updated




                                   f   Introduction to
                                       Facebook JS API
Object Model
information from graph API
    without access token




                                     f   Introduction to
                                         Facebook JS API
Graph Model
          information from graph API
               with access token




               f    Introduction to
                    Facebook JS API
Connection Model

•   All of the object in the Facebook social graph are
    connected to each other via connections

•   Objects are just like entities while connections are like
    relationship

•   For example, users, pages and groups are objects and
    likes, friends and feeds are connections




                                                    f    Introduction to
                                                         Facebook JS API
Connection Model




              f   Introduction to
                  Facebook JS API
Access to Graph
• HTTP(S) Graph API
• SDKs
  ‣   Javascript SDK

  ‣   iOS SDK

  ‣   Android SDK

  ‣   PHP SDK

  ‣   Python SDK




                       f   Introduction to
                           Facebook JS API
HTTP(S) Graph API

• RESTful HTTP request & response
• Response data-type: JSON
• Access URL: graph.facebook.com


                              f     Introduction to
                                    Facebook JS API
HTTP(S) Graph API

http://graph.facebook.com/<id-­‐or-­‐username>



•   Request information of an object with id or username

•   id-or-username can be “me” with the access token




                                              f   Introduction to
                                                  Facebook JS API
HTTP(S) Graph API
           http://graph.facebook.com/littleq0903


Result:
    {
    	
  	
  	
  "id":	
  "1681390745",
    	
  	
  	
  "name":	
  "u8607u82d1u9716",	
  //翻譯:蘇苑霖
    	
  	
  	
  "first_name":	
  "u82d1u9716",	
  //翻譯:苑霖
    	
  	
  	
  "last_name":	
  "u8607",	
  //翻譯:蘇
    	
  	
  	
  "link":	
  "https://www.facebook.com/littleq0903",
    	
  	
  	
  "username":	
  "littleq0903",
    	
  	
  	
  "gender":	
  "male",
    	
  	
  	
  "locale":	
  "en_US"
    }



                                                             f       Introduction to
                                                                     Facebook JS API
HTTP(S) Graph API

• Access token should be transferred as
  a HTTP GET variable
http://graph.facebook.com/littleq0903?access_token=...


• More information:
  developers.facebook.com/docs/
  reference/api/


                                              f   Introduction to
                                                  Facebook JS API
Access Token
•   A long string to denote the authentication of users,
    which request facebook information with your
    application

•   The information behind the access token
    ‣ user id
    ‣ app id
    ‣ expired time
    ‣ secret


                                                f   Introduction to
                                                    Facebook JS API
Javascript SDK
• Let you access all features of the Graph
  API or dialogs via Javascript
• Authentication
• Rendering the XFBML versions of
  Social Plugins
• Most functions in the FB Javascript
  SDK require an app id


                                  f     Introduction to
                                        Facebook JS API
Load the Script
• You must specify a <div> element with
  id “fb-root” in your web pages
           <div	
  id=”fb-­‐root”></div>

• The location of the script
 http://connect.facebook.net/	
  	
  	
  	
  	
  /all.js
                             en_US
                             zh_TW




                                                 f   Introduction to
                                                     Facebook JS API
Initialization
    FB.init({
    	
  	
  	
  	
  appId	
  	
  :	
  'YOUR	
  APP	
  ID',
    	
  	
  	
  	
  status	
  :	
  true,	
  //	
  check	
  login	
  status
    	
  	
  	
  	
  cookie	
  :	
  true,	
  //	
  enable	
  cookies
    	
  	
  	
  	
  xfbml	
  	
  :	
  true	
  	
  //	
  parse	
  XFBML
    	
  	
  });




• Do this after the “fb-root” div element
  has been built


                                                                             f   Introduction to
                                                                                 Facebook JS API
Components

• Core Methods
• Event Handling
• XFBML Methods
• Data Access Utilities
• Canvas Methods

                          f   Introduction to
                              Facebook JS API
Core Methods
•   FB.api(): Access the Graph API

•   FB.getLoginStatus()

•   FB.getSession()

•   FB.init(): Method of initialization

•   FB.login(): Login method

•   FB.logout(): Logout method

•   FB.ui(): Method to call dialogs


                                          f   Introduction to
                                              Facebook JS API
FB.api()
• make a API call to the Graph API
• depending on the connect status and
  the permissions
                                 Call if success.
     function	
  SuccessCall(res){
        alert(res.name);
     }


     FB.api('/me',	
  SuccessCall);


                                      f   Introduction to
                                          Facebook JS API
FB.ui()
FB.ui(
	
  	
  	
  {
	
  	
  	
  	
  	
  method:	
  'feed',
	
  	
  	
  	
  	
  name:	
  'Facebook	
  Dialogs',
	
  	
  	
  	
  	
  link:	
  'https://developers.facebook.com/docs/reference/dialogs/',
	
  	
  	
  	
  	
  picture:	
  'http://fbrell.com/f8.jpg',
	
  	
  	
  	
  	
  caption:	
  'Reference	
  Documentation',
	
  	
  	
  	
  	
  description:	
  'Dialogs	
  provide	
  a	
  simple,	
  consistent	
  interface	
  for	
  
applications	
  to	
  interface	
  with	
  users.',
	
  	
  	
  	
  	
  message:	
  'Facebook	
  Dialogs	
  are	
  easy!'
	
  	
  	
  }
	
  );



        • Triggering iframe dialogs or popups with
             Facebook

                                                                                        f     Introduction to
                                                                                              Facebook JS API
More Topics

• Event Handling
• XFBML
• FQL
• Other SDKs for Facebook Graph API

                               f   Introduction to
                                   Facebook JS API
Tools

• Javascript Console
• Debug version of Facebook JS SDK
• Test users
• URL Linter

                              f   Introduction to
                                  Facebook JS API
Examples

• js_ex1.html - Social Plugins
• js_ex2.html - FB.api()
• js_ex3.html - FB.api()
• js_ex4.html - FB.ui() & Dialogs
• Download URL: http://goo.gl/3YnnK

                                f   Introduction to
                                    Facebook JS API
Temporary HTTP Server

 • python	
  -­‐m	
  SimpleHTTPServer

 • http://127.0.0.1:8000/
 • Facebook app allow only one domain
   access at a time




                                        f   Introduction to
                                            Facebook JS API
Resources
[1] Facebook Developers
[2] jQuery - http://jquery.com
[3] Javascript tutorial - http://www.study-area.org/
coobila/category_Javascript_u6559_u5B78.html
[4] Google - http://www.google.com




                                          f   Introduction to
                                              Facebook JS API
Q&A Time
Thanks for your listening



                            f   Introduction to
                                Facebook JS API

Contenu connexe

En vedette

Workshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDKWorkshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDKDimitar Danailov
 
Introduction to Facebook JavaScript & Python SDK
Introduction to Facebook JavaScript & Python SDKIntroduction to Facebook JavaScript & Python SDK
Introduction to Facebook JavaScript & Python SDKColin Su
 
Getting started with Facebook OpenGraph API
Getting started with Facebook OpenGraph APIGetting started with Facebook OpenGraph API
Getting started with Facebook OpenGraph APILynn Langit
 
Facebook Open Graph API and How To Use It
Facebook Open Graph API and How To Use ItFacebook Open Graph API and How To Use It
Facebook Open Graph API and How To Use ItAayush Shrestha
 
Introduction to facebook javascript sdk
Introduction to facebook javascript sdk Introduction to facebook javascript sdk
Introduction to facebook javascript sdk Yi-Fan Chu
 
Facebook Open Graph API
Facebook Open Graph APIFacebook Open Graph API
Facebook Open Graph APIColin Smillie
 

En vedette (7)

Workshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDKWorkshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDK
 
Introduction to Facebook JavaScript & Python SDK
Introduction to Facebook JavaScript & Python SDKIntroduction to Facebook JavaScript & Python SDK
Introduction to Facebook JavaScript & Python SDK
 
Getting started with Facebook OpenGraph API
Getting started with Facebook OpenGraph APIGetting started with Facebook OpenGraph API
Getting started with Facebook OpenGraph API
 
Facebook Open Graph API and How To Use It
Facebook Open Graph API and How To Use ItFacebook Open Graph API and How To Use It
Facebook Open Graph API and How To Use It
 
Introduction to facebook javascript sdk
Introduction to facebook javascript sdk Introduction to facebook javascript sdk
Introduction to facebook javascript sdk
 
Facebook Open Graph API
Facebook Open Graph APIFacebook Open Graph API
Facebook Open Graph API
 
Facebook + Ruby
Facebook + RubyFacebook + Ruby
Facebook + Ruby
 

Plus de Colin Su

Introduction to Google Compute Engine
Introduction to Google Compute EngineIntroduction to Google Compute Engine
Introduction to Google Compute EngineColin Su
 
Introduction to Google Cloud Endpoints: Speed Up Your API Development
Introduction to Google Cloud Endpoints: Speed Up Your API DevelopmentIntroduction to Google Cloud Endpoints: Speed Up Your API Development
Introduction to Google Cloud Endpoints: Speed Up Your API DevelopmentColin Su
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in PythonColin Su
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code LabColin Su
 
A Tour of Google Cloud Platform
A Tour of Google Cloud PlatformA Tour of Google Cloud Platform
A Tour of Google Cloud PlatformColin Su
 
Introduction to MapReduce & hadoop
Introduction to MapReduce & hadoopIntroduction to MapReduce & hadoop
Introduction to MapReduce & hadoopColin Su
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App EngineColin Su
 
Django Deployer
Django DeployerDjango Deployer
Django DeployerColin Su
 
Introduction to Google - the most natural way to learn English (English Speech)
Introduction to Google - the most natural way to learn English (English Speech)Introduction to Google - the most natural way to learn English (English Speech)
Introduction to Google - the most natural way to learn English (English Speech)Colin Su
 
How to Speak Charms Like a Wizard
How to Speak Charms Like a WizardHow to Speak Charms Like a Wizard
How to Speak Charms Like a WizardColin Su
 
房地產報告
房地產報告房地產報告
房地產報告Colin Su
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to GitColin Su
 
Introduction to Facebook Python API
Introduction to Facebook Python APIIntroduction to Facebook Python API
Introduction to Facebook Python APIColin Su
 
Facebook Python SDK - Introduction
Facebook Python SDK - IntroductionFacebook Python SDK - Introduction
Facebook Python SDK - IntroductionColin Su
 
Web Programming - 1st TA Session
Web Programming - 1st TA SessionWeb Programming - 1st TA Session
Web Programming - 1st TA SessionColin Su
 
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary SearchNested List Comprehension and Binary Search
Nested List Comprehension and Binary SearchColin Su
 
Python-List comprehension
Python-List comprehensionPython-List comprehension
Python-List comprehensionColin Su
 
Python-FileIO
Python-FileIOPython-FileIO
Python-FileIOColin Su
 
Python Dictionary
Python DictionaryPython Dictionary
Python DictionaryColin Su
 
Vim editor
Vim editorVim editor
Vim editorColin Su
 

Plus de Colin Su (20)

Introduction to Google Compute Engine
Introduction to Google Compute EngineIntroduction to Google Compute Engine
Introduction to Google Compute Engine
 
Introduction to Google Cloud Endpoints: Speed Up Your API Development
Introduction to Google Cloud Endpoints: Speed Up Your API DevelopmentIntroduction to Google Cloud Endpoints: Speed Up Your API Development
Introduction to Google Cloud Endpoints: Speed Up Your API Development
 
Functional programming in Python
Functional programming in PythonFunctional programming in Python
Functional programming in Python
 
Web2py Code Lab
Web2py Code LabWeb2py Code Lab
Web2py Code Lab
 
A Tour of Google Cloud Platform
A Tour of Google Cloud PlatformA Tour of Google Cloud Platform
A Tour of Google Cloud Platform
 
Introduction to MapReduce & hadoop
Introduction to MapReduce & hadoopIntroduction to MapReduce & hadoop
Introduction to MapReduce & hadoop
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
Django Deployer
Django DeployerDjango Deployer
Django Deployer
 
Introduction to Google - the most natural way to learn English (English Speech)
Introduction to Google - the most natural way to learn English (English Speech)Introduction to Google - the most natural way to learn English (English Speech)
Introduction to Google - the most natural way to learn English (English Speech)
 
How to Speak Charms Like a Wizard
How to Speak Charms Like a WizardHow to Speak Charms Like a Wizard
How to Speak Charms Like a Wizard
 
房地產報告
房地產報告房地產報告
房地產報告
 
Introduction to Git
Introduction to GitIntroduction to Git
Introduction to Git
 
Introduction to Facebook Python API
Introduction to Facebook Python APIIntroduction to Facebook Python API
Introduction to Facebook Python API
 
Facebook Python SDK - Introduction
Facebook Python SDK - IntroductionFacebook Python SDK - Introduction
Facebook Python SDK - Introduction
 
Web Programming - 1st TA Session
Web Programming - 1st TA SessionWeb Programming - 1st TA Session
Web Programming - 1st TA Session
 
Nested List Comprehension and Binary Search
Nested List Comprehension and Binary SearchNested List Comprehension and Binary Search
Nested List Comprehension and Binary Search
 
Python-List comprehension
Python-List comprehensionPython-List comprehension
Python-List comprehension
 
Python-FileIO
Python-FileIOPython-FileIO
Python-FileIO
 
Python Dictionary
Python DictionaryPython Dictionary
Python Dictionary
 
Vim editor
Vim editorVim editor
Vim editor
 

Dernier

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsJoaquim Jorge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 

Dernier (20)

How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 

Introduction to Facebook Javascript SDK

  • 1. API Introduction to Facebook Javascript API Social Network and Applications, 2011 LittleQ, The department of Computer Science, NCCU f Introduction to Facebook JS API
  • 2. Objectives • Learn the concepts of Facebook API • Learn how to use Facebook API with Javascript f Introduction to Facebook JS API
  • 3. Core Topics • Facebook Developers website • Graph API • Facebook Javascript SDK • Resources f Introduction to Facebook JS API
  • 4. Facebook Developers • Provide you online documentations • Forum for discussion • Management of your applications f Introduction to Facebook JS API
  • 5. Where is it? f Introduction to Facebook JS API
  • 6. Social Plugins • Like Button, Send Button, Login Button • Comments • Registration • Activity Feed, Live Stream f Introduction to Facebook JS API
  • 7. Graph API Response Data Aggregate Information Access Token Request Data Application Graph API Facebook Database • Facebook’s core • Social graph • Connections f Introduction to Facebook JS API
  • 8. Graph Model • Composed of objects and connections • Identify entities and relationships by id • Data will be stored with smallest spaces and keep being updated f Introduction to Facebook JS API
  • 9. Object Model information from graph API without access token f Introduction to Facebook JS API
  • 10. Graph Model information from graph API with access token f Introduction to Facebook JS API
  • 11. Connection Model • All of the object in the Facebook social graph are connected to each other via connections • Objects are just like entities while connections are like relationship • For example, users, pages and groups are objects and likes, friends and feeds are connections f Introduction to Facebook JS API
  • 12. Connection Model f Introduction to Facebook JS API
  • 13. Access to Graph • HTTP(S) Graph API • SDKs ‣ Javascript SDK ‣ iOS SDK ‣ Android SDK ‣ PHP SDK ‣ Python SDK f Introduction to Facebook JS API
  • 14. HTTP(S) Graph API • RESTful HTTP request & response • Response data-type: JSON • Access URL: graph.facebook.com f Introduction to Facebook JS API
  • 15. HTTP(S) Graph API http://graph.facebook.com/<id-­‐or-­‐username> • Request information of an object with id or username • id-or-username can be “me” with the access token f Introduction to Facebook JS API
  • 16. HTTP(S) Graph API http://graph.facebook.com/littleq0903 Result: {      "id":  "1681390745",      "name":  "u8607u82d1u9716",  //翻譯:蘇苑霖      "first_name":  "u82d1u9716",  //翻譯:苑霖      "last_name":  "u8607",  //翻譯:蘇      "link":  "https://www.facebook.com/littleq0903",      "username":  "littleq0903",      "gender":  "male",      "locale":  "en_US" } f Introduction to Facebook JS API
  • 17. HTTP(S) Graph API • Access token should be transferred as a HTTP GET variable http://graph.facebook.com/littleq0903?access_token=... • More information: developers.facebook.com/docs/ reference/api/ f Introduction to Facebook JS API
  • 18. Access Token • A long string to denote the authentication of users, which request facebook information with your application • The information behind the access token ‣ user id ‣ app id ‣ expired time ‣ secret f Introduction to Facebook JS API
  • 19. Javascript SDK • Let you access all features of the Graph API or dialogs via Javascript • Authentication • Rendering the XFBML versions of Social Plugins • Most functions in the FB Javascript SDK require an app id f Introduction to Facebook JS API
  • 20. Load the Script • You must specify a <div> element with id “fb-root” in your web pages <div  id=”fb-­‐root”></div> • The location of the script http://connect.facebook.net/          /all.js en_US zh_TW f Introduction to Facebook JS API
  • 21. Initialization FB.init({        appId    :  'YOUR  APP  ID',        status  :  true,  //  check  login  status        cookie  :  true,  //  enable  cookies        xfbml    :  true    //  parse  XFBML    }); • Do this after the “fb-root” div element has been built f Introduction to Facebook JS API
  • 22. Components • Core Methods • Event Handling • XFBML Methods • Data Access Utilities • Canvas Methods f Introduction to Facebook JS API
  • 23. Core Methods • FB.api(): Access the Graph API • FB.getLoginStatus() • FB.getSession() • FB.init(): Method of initialization • FB.login(): Login method • FB.logout(): Logout method • FB.ui(): Method to call dialogs f Introduction to Facebook JS API
  • 24. FB.api() • make a API call to the Graph API • depending on the connect status and the permissions Call if success. function  SuccessCall(res){ alert(res.name); } FB.api('/me',  SuccessCall); f Introduction to Facebook JS API
  • 25. FB.ui() FB.ui(      {          method:  'feed',          name:  'Facebook  Dialogs',          link:  'https://developers.facebook.com/docs/reference/dialogs/',          picture:  'http://fbrell.com/f8.jpg',          caption:  'Reference  Documentation',          description:  'Dialogs  provide  a  simple,  consistent  interface  for   applications  to  interface  with  users.',          message:  'Facebook  Dialogs  are  easy!'      }  ); • Triggering iframe dialogs or popups with Facebook f Introduction to Facebook JS API
  • 26. More Topics • Event Handling • XFBML • FQL • Other SDKs for Facebook Graph API f Introduction to Facebook JS API
  • 27. Tools • Javascript Console • Debug version of Facebook JS SDK • Test users • URL Linter f Introduction to Facebook JS API
  • 28. Examples • js_ex1.html - Social Plugins • js_ex2.html - FB.api() • js_ex3.html - FB.api() • js_ex4.html - FB.ui() & Dialogs • Download URL: http://goo.gl/3YnnK f Introduction to Facebook JS API
  • 29. Temporary HTTP Server • python  -­‐m  SimpleHTTPServer • http://127.0.0.1:8000/ • Facebook app allow only one domain access at a time f Introduction to Facebook JS API
  • 30. Resources [1] Facebook Developers [2] jQuery - http://jquery.com [3] Javascript tutorial - http://www.study-area.org/ coobila/category_Javascript_u6559_u5B78.html [4] Google - http://www.google.com f Introduction to Facebook JS API
  • 31. Q&A Time Thanks for your listening f Introduction to Facebook JS API