SlideShare una empresa de Scribd logo
1 de 49
Descargar para leer sin conexión
Facebook Graph API
Thiwat Rongsirigul Thai Pangsakulaynont
Khanet Krongkitichu
This presentation is part of group presentation assignment in 01219321 Data Communications and Network Programming,
a Software and Knowledge Engineering undergraduate course, Kasetsart University.
Outline
Graph API
OAuth 2
Demos
Documentation
http://developers.facebook.com/
{
"id": "617920932",
"first_name": "Beammagic",
"gender": "male",
"last_name": "Goldenfish",
"link": "https://www.facebook.com/beammagic",
"locale": "en_US",
"name": "Beammagic Goldenfish",
"username": "beammagic"
}
https://graph.facebook.com/beammagic
JSON API
Example Usage
<div id="message">
<span id="name">(page name)</span> has
<span id="likes">(number)</span> likes.
</div>
var promise = $.get('https://graph.facebook.com/thapster')
Example Usage
<div id="message">
<span id="name">(page name)</span> has
<span id="likes">(number)</span> likes.
</div>
var promise = $.get('https://graph.facebook.com/thapster')
promise.done(function(info) {
})
Example Usage
<div id="message">
<span id="name">(page name)</span> has
<span id="likes">(number)</span> likes.
</div>
var promise = $.get('https://graph.facebook.com/thapster')
promise.done(function(info) {
$('#name').text(info.name)
$('#likes').text(info.likes)
})
Demo
Graph API Explorer
https://developers.facebook.com/tools/explorer/
Go!!
Graph API Reference
https://developers.facebook.com
/docs/graph-api/reference/
Go!!
{
"error": {
"message": "An active access token must be used to
query information about the current user.",
"type": "OAuthException",
"code": 2500
}
}
https://graph.facebook.com/me
JSON API
Facebook does not know
who you are…
OAuth 2
https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/
Everyone has an
access_token for
each app.
{
"error": {
"message": "An active access token must be used to
query information about the current user.",
"type": "OAuthException",
"code": 2500
}
}
https://graph.facebook.com/me
OAuth 2
{
"id": "1658509977",
"first_name": "Thai",
"gender": "male",
"last_name": "Pangsakulyanont",
"link": "https://www.facebook.com/dtinth",
"locale": "en_US",
"name": "Thai Pangsakulyanont",
"timezone": 7,
"updated_time": "2014-04-03T09:38:10+0000",
"username": "dtinth",
https://graph.facebook.com/me?access_token=o7pzkF
OAuth 2
I can haz my
access_token?
OAuth 2 Token Flow
(Client-Side Flow with JavaScript)
1. Check access_token!
var accessToken = localStorage.accessToken
function checkUser(callback) {
if (!accessToken) { pleaseLogin(); return }
$.get('https://graph.facebook.com/me?access_token=' + accessToken)
.then(function(profile) { callback(profile) })
.fail(function(error) { pleaseLogin() })
}
checkUser(function(profile) {
// this code will run if user is logged in
})
1. Check access_token!
var accessToken = localStorage.accessToken
function checkUser(callback) {
if (!accessToken) { pleaseLogin(); return }
$.get('https://graph.facebook.com/me?access_token=' + accessToken)
.then(function(profile) { callback(profile) })
.fail(function(error) { pleaseLogin() })
}
checkUser(function(profile) {
$('.your-name').text(profile.name)
})
1. Check access_token!
var accessToken = localStorage.accessToken
function checkUser(callback) {
if (!accessToken) { pleaseLogin(); return }
$.get('https://graph.facebook.com/me?access_token=' + accessToken)
.then(function(profile) { callback(profile) })
.fail(function(error) { pleaseLogin() })
}
checkUser(function(profile) {
$('.your-name').text(profile.name)
})
1. Check access_token!
var accessToken = localStorage.accessToken
function checkUser(callback) {
if (!accessToken) { pleaseLogin(); return }
$.get('https://graph.facebook.com/me?access_token=' + accessToken)
.then(function(profile) { callback(profile) })
.fail(function(error) { pleaseLogin() })
}
checkUser(function(profile) {
$('.your-name').text(profile.name)
})
1. Check access_token!
var accessToken = localStorage.accessToken
function checkUser(callback) {
if (!accessToken) { pleaseLogin(); return }
$.get('https://graph.facebook.com/me?access_token=' + accessToken)
.done(function(profile) { callback(profile) })
.fail(function(error) { pleaseLogin() })
}
checkUser(function(profile) {
$('.your-name').text(profile.name)
})
2. Create login button!
facebook
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
2. Create login button!
function pleaseLogin() {
var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903&response_type=token' +
'&redirect_uri=' + redirect +
'&scope=publish_stream'
$('#logged-in').hide()
$('#error-message').show()
$('#error-message-text').text('Please login!')
$('#login-button').attr('href', url)
}
3. User authorizes application
for basic access
4. User grants extended permission
var url = 'https://www.facebook.com/dialog/oauth' +
'?client_id=269104936600903' +
'&response_type=token&redirect_uri=' + redirect +
'&scope=publish_stream'
5. Facebook sends back access token!
6. Save the access token!
<h1>Thanks for logging in!</h1>
<script>
var match = location.hash.match(/access_token=([^&]+)/)
if (match) {
var token = match[1]
localStorage.accessToken = token
location.replace('index.html')
} else {
alert("I do not have your access token! Something must be wro
}
</script>
6. Save the access token!
<h1>Thanks for logging in!</h1>
<script>
var match = location.hash.match(/access_token=([^&]+)/)
if (match) {
var token = match[1]
localStorage.accessToken = token
location.replace('index.html')
} else {
alert("I do not have your access token! Something must be wro
}
</script>
6. Save the access token!
<h1>Thanks for logging in!</h1>
<script>
var match = location.hash.match(/access_token=([^&]+)/)
if (match) {
var token = match[1]
localStorage.accessToken = token
location.replace('index.html')
} else {
alert("I do not have your access token! Something must be wro
}
</script>
6. Save the access token!
<h1>Thanks for logging in!</h1>
<script>
var match = location.hash.match(/access_token=([^&]+)/)
if (match) {
var token = match[1]
localStorage.accessToken = token
location.replace('index.html')
} else {
alert("I do not have your access token! Something must be wro
}
</script>
6. Save the access token!
<h1>Thanks for logging in!</h1>
<script>
var match = location.hash.match(/access_token=([^&]+)/)
if (match) {
var token = match[1]
localStorage.accessToken = token
location.replace('index.html')
} else {
alert("I do not have your access token! Something must be wro
}
</script>
checkUser(function(profile) {
$('.your-name').text(profile.name)
})
<div id="logged-in">
<p>Welcome, <span class="your-name"></span></p>
</div>
Welcome, Thai Pangsakulyanont
$('#button').click(function() {
$.post('https://graph.facebook.com/me/feed' +
'?access_token=' + accessToken,
{ message: message })
.done(function() { /* ... */ })
.fail(function() { showError('Cannot post.') })
})
Demonstration!
https://c9.io/dtinth/datacomdemo
Slide: http://bit.ly/fb-ws

Más contenido relacionado

La actualidad más candente

Intro to developing for @twitterapi
Intro to developing for @twitterapiIntro to developing for @twitterapi
Intro to developing for @twitterapi
Raffi Krikorian
 
The Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve itThe Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve it
Bastian Hofmann
 
Cbcode volume2
Cbcode volume2Cbcode volume2
Cbcode volume2
Madfex
 
Facebook Apps: Ein Entwicklungsleitfaden - WMMRN
Facebook Apps: Ein Entwicklungsleitfaden - WMMRNFacebook Apps: Ein Entwicklungsleitfaden - WMMRN
Facebook Apps: Ein Entwicklungsleitfaden - WMMRN
Stephan Hochdörfer
 

La actualidad más candente (20)

Intro to developing for @twitterapi
Intro to developing for @twitterapiIntro to developing for @twitterapi
Intro to developing for @twitterapi
 
Try Web Components
Try Web ComponentsTry Web Components
Try Web Components
 
The Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve itThe Identity Problem of the Web and how to solve it
The Identity Problem of the Web and how to solve it
 
What's happening here?
What's happening here?What's happening here?
What's happening here?
 
Rest experience-report
Rest experience-reportRest experience-report
Rest experience-report
 
Introduction to jQuery Mobile - Web Deliver for All
Introduction to jQuery Mobile - Web Deliver for AllIntroduction to jQuery Mobile - Web Deliver for All
Introduction to jQuery Mobile - Web Deliver for All
 
Cbcode volume2
Cbcode volume2Cbcode volume2
Cbcode volume2
 
Building jQuery Mobile Web Apps
Building jQuery Mobile Web AppsBuilding jQuery Mobile Web Apps
Building jQuery Mobile Web Apps
 
Workshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDKWorkshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDK
 
Introduction to Facebook Javascript SDK (NEW)
Introduction to Facebook Javascript SDK (NEW)Introduction to Facebook Javascript SDK (NEW)
Introduction to Facebook Javascript SDK (NEW)
 
社文字D: 轟趴開交物語
社文字D: 轟趴開交物語社文字D: 轟趴開交物語
社文字D: 轟趴開交物語
 
Rb link database
Rb link databaseRb link database
Rb link database
 
You're still using passwords on your site?
You're still using passwords on your site?You're still using passwords on your site?
You're still using passwords on your site?
 
iWebkit
iWebkitiWebkit
iWebkit
 
USC Yahoo! BOSS, YAP and YQL Overview
USC Yahoo! BOSS, YAP and YQL OverviewUSC Yahoo! BOSS, YAP and YQL Overview
USC Yahoo! BOSS, YAP and YQL Overview
 
CIS13: Identity Tech Overview: Less Pain, More Gain
CIS13: Identity Tech Overview: Less Pain, More GainCIS13: Identity Tech Overview: Less Pain, More Gain
CIS13: Identity Tech Overview: Less Pain, More Gain
 
Building Consistent RESTful APIs in a high-performance environment
Building Consistent RESTful APIs in a high-performance environmentBuilding Consistent RESTful APIs in a high-performance environment
Building Consistent RESTful APIs in a high-performance environment
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on Rails
 
Facebook Apps: Ein Entwicklungsleitfaden - WMMRN
Facebook Apps: Ein Entwicklungsleitfaden - WMMRNFacebook Apps: Ein Entwicklungsleitfaden - WMMRN
Facebook Apps: Ein Entwicklungsleitfaden - WMMRN
 
Journalism and the Future of Mobile
Journalism and the Future of MobileJournalism and the Future of Mobile
Journalism and the Future of Mobile
 

Destacado

Hive undocumented feature
Hive undocumented featureHive undocumented feature
Hive undocumented feature
tamtam180
 
動画共有ツール
動画共有ツール動画共有ツール
動画共有ツール
tamtam180
 
Facebook Open Graph Api
Facebook Open Graph ApiFacebook Open Graph Api
Facebook Open Graph Api
Simon Li
 

Destacado (20)

Facebook Open Graph API
Facebook Open Graph APIFacebook Open Graph API
Facebook Open Graph 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
 
Hive undocumented feature
Hive undocumented featureHive undocumented feature
Hive undocumented feature
 
動画共有ツール
動画共有ツール動画共有ツール
動画共有ツール
 
Understanding the potential of the Facebook Open Graph and Graph API
Understanding the potential of the Facebook Open Graph and Graph APIUnderstanding the potential of the Facebook Open Graph and Graph API
Understanding the potential of the Facebook Open Graph and Graph API
 
How to Leverage the Social Graph with Facebook Platform
How to Leverage the Social Graph with Facebook PlatformHow to Leverage the Social Graph with Facebook Platform
How to Leverage the Social Graph with Facebook Platform
 
Graph Theory and Databases
Graph Theory and DatabasesGraph Theory and Databases
Graph Theory and Databases
 
Graph basic
Graph basicGraph basic
Graph basic
 
What is the Facebook Open Graph
What is the Facebook Open GraphWhat is the Facebook Open Graph
What is the Facebook Open Graph
 
Facebook Open Graph 6.10.10
Facebook Open Graph 6.10.10Facebook Open Graph 6.10.10
Facebook Open Graph 6.10.10
 
Facebook permission
Facebook permissionFacebook permission
Facebook permission
 
The New Facebook: A Brand's Perspective
The New Facebook:  A Brand's Perspective The New Facebook:  A Brand's Perspective
The New Facebook: A Brand's Perspective
 
"Introduction Open Graph and Facebook Platform" - Facebook Developer Garage ...
"Introduction Open Graph and Facebook Platform" -  Facebook Developer Garage ..."Introduction Open Graph and Facebook Platform" -  Facebook Developer Garage ...
"Introduction Open Graph and Facebook Platform" - Facebook Developer Garage ...
 
Facebook Open Graph - The Semantic Wallet
Facebook Open Graph - The Semantic WalletFacebook Open Graph - The Semantic Wallet
Facebook Open Graph - The Semantic Wallet
 
Facebook Open Graph
Facebook Open GraphFacebook Open Graph
Facebook Open Graph
 
Facebook Open Graph, Social Plug ins and Privacy -- what they mean to you
Facebook Open Graph, Social Plug ins and Privacy -- what they mean to youFacebook Open Graph, Social Plug ins and Privacy -- what they mean to you
Facebook Open Graph, Social Plug ins and Privacy -- what they mean to you
 
Open Graph & oEmbed | facebook的開放社交關係圖與其他網站的oEmbed
Open Graph & oEmbed | facebook的開放社交關係圖與其他網站的oEmbedOpen Graph & oEmbed | facebook的開放社交關係圖與其他網站的oEmbed
Open Graph & oEmbed | facebook的開放社交關係圖與其他網站的oEmbed
 
Facebook Open Graph Api
Facebook Open Graph ApiFacebook Open Graph Api
Facebook Open Graph Api
 
Facebook Open Graph Protocol
Facebook Open Graph ProtocolFacebook Open Graph Protocol
Facebook Open Graph Protocol
 
LiveWorld POV for FaceBook's Timeline API
LiveWorld POV for FaceBook's Timeline APILiveWorld POV for FaceBook's Timeline API
LiveWorld POV for FaceBook's Timeline API
 

Similar a Introduction to Facebook Graph API and OAuth 2

Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
danwrong
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQuery
Doncho Minkov
 

Similar a Introduction to Facebook Graph API and OAuth 2 (20)

Mashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web AppsMashing up JavaScript – Advanced Techniques for modern Web Apps
Mashing up JavaScript – Advanced Techniques for modern Web Apps
 
Mashing up JavaScript
Mashing up JavaScriptMashing up JavaScript
Mashing up JavaScript
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricks
 
QA Fest 2017. Ярослав Святкин. Тестовый фреймворк GEB для тестирования WEB пр...
QA Fest 2017. Ярослав Святкин. Тестовый фреймворк GEB для тестирования WEB пр...QA Fest 2017. Ярослав Святкин. Тестовый фреймворк GEB для тестирования WEB пр...
QA Fest 2017. Ярослав Святкин. Тестовый фреймворк GEB для тестирования WEB пр...
 
Geb qa fest2017
Geb qa fest2017Geb qa fest2017
Geb qa fest2017
 
Django - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazosDjango - Framework web para perfeccionistas com prazos
Django - Framework web para perfeccionistas com prazos
 
An Introduction to Jquery
An Introduction to JqueryAn Introduction to Jquery
An Introduction to Jquery
 
FamilySearch Reference Client
FamilySearch Reference ClientFamilySearch Reference Client
FamilySearch Reference Client
 
Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4Python Code Camp for Professionals 1/4
Python Code Camp for Professionals 1/4
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in Swift
 
Django
DjangoDjango
Django
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)
 
Pengenalan AngularJS
Pengenalan AngularJSPengenalan AngularJS
Pengenalan AngularJS
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”
 
Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers Steal
 
Cross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App EngineCross Domain Web
Mashups with JQuery and Google App Engine
Cross Domain Web
Mashups with JQuery and Google App Engine
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQuery
 
Building iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" DominoBuilding iPhone Web Apps using "classic" Domino
Building iPhone Web Apps using "classic" Domino
 
Acceptance Testing with Webrat
Acceptance Testing with WebratAcceptance Testing with Webrat
Acceptance Testing with Webrat
 

Último

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Último (20)

A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 

Introduction to Facebook Graph API and OAuth 2

  • 1. Facebook Graph API Thiwat Rongsirigul Thai Pangsakulaynont Khanet Krongkitichu This presentation is part of group presentation assignment in 01219321 Data Communications and Network Programming, a Software and Knowledge Engineering undergraduate course, Kasetsart University.
  • 4. { "id": "617920932", "first_name": "Beammagic", "gender": "male", "last_name": "Goldenfish", "link": "https://www.facebook.com/beammagic", "locale": "en_US", "name": "Beammagic Goldenfish", "username": "beammagic" } https://graph.facebook.com/beammagic JSON API
  • 5. Example Usage <div id="message"> <span id="name">(page name)</span> has <span id="likes">(number)</span> likes. </div> var promise = $.get('https://graph.facebook.com/thapster')
  • 6. Example Usage <div id="message"> <span id="name">(page name)</span> has <span id="likes">(number)</span> likes. </div> var promise = $.get('https://graph.facebook.com/thapster') promise.done(function(info) { })
  • 7. Example Usage <div id="message"> <span id="name">(page name)</span> has <span id="likes">(number)</span> likes. </div> var promise = $.get('https://graph.facebook.com/thapster') promise.done(function(info) { $('#name').text(info.name) $('#likes').text(info.likes) }) Demo
  • 10. { "error": { "message": "An active access token must be used to query information about the current user.", "type": "OAuthException", "code": 2500 } } https://graph.facebook.com/me JSON API
  • 11. Facebook does not know who you are…
  • 14. { "error": { "message": "An active access token must be used to query information about the current user.", "type": "OAuthException", "code": 2500 } } https://graph.facebook.com/me OAuth 2
  • 15. { "id": "1658509977", "first_name": "Thai", "gender": "male", "last_name": "Pangsakulyanont", "link": "https://www.facebook.com/dtinth", "locale": "en_US", "name": "Thai Pangsakulyanont", "timezone": 7, "updated_time": "2014-04-03T09:38:10+0000", "username": "dtinth", https://graph.facebook.com/me?access_token=o7pzkF OAuth 2
  • 16. I can haz my access_token?
  • 17. OAuth 2 Token Flow (Client-Side Flow with JavaScript)
  • 18.
  • 19.
  • 20.
  • 21. 1. Check access_token! var accessToken = localStorage.accessToken function checkUser(callback) { if (!accessToken) { pleaseLogin(); return } $.get('https://graph.facebook.com/me?access_token=' + accessToken) .then(function(profile) { callback(profile) }) .fail(function(error) { pleaseLogin() }) } checkUser(function(profile) { // this code will run if user is logged in })
  • 22. 1. Check access_token! var accessToken = localStorage.accessToken function checkUser(callback) { if (!accessToken) { pleaseLogin(); return } $.get('https://graph.facebook.com/me?access_token=' + accessToken) .then(function(profile) { callback(profile) }) .fail(function(error) { pleaseLogin() }) } checkUser(function(profile) { $('.your-name').text(profile.name) })
  • 23. 1. Check access_token! var accessToken = localStorage.accessToken function checkUser(callback) { if (!accessToken) { pleaseLogin(); return } $.get('https://graph.facebook.com/me?access_token=' + accessToken) .then(function(profile) { callback(profile) }) .fail(function(error) { pleaseLogin() }) } checkUser(function(profile) { $('.your-name').text(profile.name) })
  • 24. 1. Check access_token! var accessToken = localStorage.accessToken function checkUser(callback) { if (!accessToken) { pleaseLogin(); return } $.get('https://graph.facebook.com/me?access_token=' + accessToken) .then(function(profile) { callback(profile) }) .fail(function(error) { pleaseLogin() }) } checkUser(function(profile) { $('.your-name').text(profile.name) })
  • 25. 1. Check access_token! var accessToken = localStorage.accessToken function checkUser(callback) { if (!accessToken) { pleaseLogin(); return } $.get('https://graph.facebook.com/me?access_token=' + accessToken) .done(function(profile) { callback(profile) }) .fail(function(error) { pleaseLogin() }) } checkUser(function(profile) { $('.your-name').text(profile.name) })
  • 26. 2. Create login button! facebook
  • 27. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 28. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 29.
  • 30. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 31. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 32. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 33. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 34. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 35. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 36. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 37. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 38. 2. Create login button! function pleaseLogin() { var redirect = 'https://c9.io/dtinth/datacomdemo/workspace/callback.h var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903&response_type=token' + '&redirect_uri=' + redirect + '&scope=publish_stream' $('#logged-in').hide() $('#error-message').show() $('#error-message-text').text('Please login!') $('#login-button').attr('href', url) }
  • 39. 3. User authorizes application for basic access
  • 40. 4. User grants extended permission var url = 'https://www.facebook.com/dialog/oauth' + '?client_id=269104936600903' + '&response_type=token&redirect_uri=' + redirect + '&scope=publish_stream'
  • 41. 5. Facebook sends back access token!
  • 42. 6. Save the access token! <h1>Thanks for logging in!</h1> <script> var match = location.hash.match(/access_token=([^&]+)/) if (match) { var token = match[1] localStorage.accessToken = token location.replace('index.html') } else { alert("I do not have your access token! Something must be wro } </script>
  • 43. 6. Save the access token! <h1>Thanks for logging in!</h1> <script> var match = location.hash.match(/access_token=([^&]+)/) if (match) { var token = match[1] localStorage.accessToken = token location.replace('index.html') } else { alert("I do not have your access token! Something must be wro } </script>
  • 44. 6. Save the access token! <h1>Thanks for logging in!</h1> <script> var match = location.hash.match(/access_token=([^&]+)/) if (match) { var token = match[1] localStorage.accessToken = token location.replace('index.html') } else { alert("I do not have your access token! Something must be wro } </script>
  • 45. 6. Save the access token! <h1>Thanks for logging in!</h1> <script> var match = location.hash.match(/access_token=([^&]+)/) if (match) { var token = match[1] localStorage.accessToken = token location.replace('index.html') } else { alert("I do not have your access token! Something must be wro } </script>
  • 46. 6. Save the access token! <h1>Thanks for logging in!</h1> <script> var match = location.hash.match(/access_token=([^&]+)/) if (match) { var token = match[1] localStorage.accessToken = token location.replace('index.html') } else { alert("I do not have your access token! Something must be wro } </script>
  • 47. checkUser(function(profile) { $('.your-name').text(profile.name) }) <div id="logged-in"> <p>Welcome, <span class="your-name"></span></p> </div> Welcome, Thai Pangsakulyanont
  • 48. $('#button').click(function() { $.post('https://graph.facebook.com/me/feed' + '?access_token=' + accessToken, { message: message }) .done(function() { /* ... */ }) .fail(function() { showError('Cannot post.') }) })