SlideShare a Scribd company logo
1 of 49
Download to read offline
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

More Related Content

What's hot

Intro to developing for @twitterapi
Intro to developing for @twitterapiIntro to developing for @twitterapi
Intro to developing for @twitterapiRaffi Krikorian
 
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 itBastian Hofmann
 
Rest experience-report
Rest experience-reportRest experience-report
Rest experience-reportJim Barritt
 
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 AllMarc Grabanski
 
Cbcode volume2
Cbcode volume2Cbcode volume2
Cbcode volume2Madfex
 
Building jQuery Mobile Web Apps
Building jQuery Mobile Web AppsBuilding jQuery Mobile Web Apps
Building jQuery Mobile Web AppsOperation Mobile
 
Workshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDKWorkshop : Facebook JavaScript SDK
Workshop : Facebook JavaScript SDKDimitar Danailov
 
Introduction to Facebook Javascript SDK (NEW)
Introduction to Facebook Javascript SDK (NEW)Introduction to Facebook Javascript SDK (NEW)
Introduction to Facebook Javascript SDK (NEW)Colin Su
 
社文字D: 轟趴開交物語
社文字D: 轟趴開交物語社文字D: 轟趴開交物語
社文字D: 轟趴開交物語Audrey Tang
 
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?Francois Marier
 
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 OverviewJonathan LeBlanc
 
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 GainCloudIDSummit
 
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 environmentLinkedIn
 
Boston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsBoston Computing Review - Ruby on Rails
Boston Computing Review - Ruby on RailsJohn Brunswick
 
Facebook Apps: Ein Entwicklungsleitfaden - WMMRN
Facebook Apps: Ein Entwicklungsleitfaden - WMMRNFacebook Apps: Ein Entwicklungsleitfaden - WMMRN
Facebook Apps: Ein Entwicklungsleitfaden - WMMRNStephan Hochdörfer
 
Journalism and the Future of Mobile
Journalism and the Future of MobileJournalism and the Future of Mobile
Journalism and the Future of MobileJason Grigsby
 

What's hot (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
 

Viewers also liked

Facebook Open Graph API
Facebook Open Graph APIFacebook Open Graph API
Facebook Open Graph APIColin Smillie
 
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
 
Hive undocumented feature
Hive undocumented featureHive undocumented feature
Hive undocumented featuretamtam180
 
動画共有ツール
動画共有ツール動画共有ツール
動画共有ツールtamtam180
 
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 APIMeddle
 
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 PlatformDave Olsen
 
What is the Facebook Open Graph
What is the Facebook Open GraphWhat is the Facebook Open Graph
What is the Facebook Open GraphJay Feitlinger
 
Facebook Open Graph 6.10.10
Facebook Open Graph 6.10.10Facebook Open Graph 6.10.10
Facebook Open Graph 6.10.10MITX
 
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 Carve
 
"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 ...Vijay Rayapati
 
Facebook Open Graph - The Semantic Wallet
Facebook Open Graph - The Semantic WalletFacebook Open Graph - The Semantic Wallet
Facebook Open Graph - The Semantic WalletJonathan Laba
 
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 youDoug McIsaac
 
Open Graph & oEmbed | facebook的開放社交關係圖與其他網站的oEmbed
Open Graph & oEmbed | facebook的開放社交關係圖與其他網站的oEmbedOpen Graph & oEmbed | facebook的開放社交關係圖與其他網站的oEmbed
Open Graph & oEmbed | facebook的開放社交關係圖與其他網站的oEmbedVeronica Lin
 
Facebook Open Graph Api
Facebook Open Graph ApiFacebook Open Graph Api
Facebook Open Graph ApiSimon Li
 
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 APILiveWorld
 

Viewers also liked (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 to Introduction to Facebook Graph API and OAuth 2

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 AppsBastian Hofmann
 
Cheap frontend tricks
Cheap frontend tricksCheap frontend tricks
Cheap frontend tricksambiescent
 
QA Fest 2017. Ярослав Святкин. Тестовый фреймворк GEB для тестирования WEB пр...
QA Fest 2017. Ярослав Святкин. Тестовый фреймворк GEB для тестирования WEB пр...QA Fest 2017. Ярослав Святкин. Тестовый фреймворк GEB для тестирования WEB пр...
QA Fest 2017. Ярослав Святкин. Тестовый фреймворк GEB для тестирования WEB пр...QAFest
 
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 prazosIgor Sobreira
 
An Introduction to Jquery
An Introduction to JqueryAn Introduction to Jquery
An Introduction to JqueryPhil Reither
 
FamilySearch Reference Client
FamilySearch Reference ClientFamilySearch Reference Client
FamilySearch Reference ClientDallan Quass
 
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/4DEVCON
 
async/await in Swift
async/await in Swiftasync/await in Swift
async/await in SwiftPeter Friese
 
Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)Building @Anywhere (for TXJS)
Building @Anywhere (for TXJS)danwrong
 
Pengenalan AngularJS
Pengenalan AngularJSPengenalan AngularJS
Pengenalan AngularJSEdi Santoso
 
RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”RubyBarCamp “Полезные gems и plugins”
RubyBarCamp “Полезные gems и plugins”apostlion
 
Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rugalytics | Ruby Manor Nov 2008
Rugalytics | Ruby Manor Nov 2008Rob
 
Great Developers Steal
Great Developers StealGreat Developers Steal
Great Developers StealBen Scofield
 
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 EngineAndy McKay
 
External Data Access with jQuery
External Data Access with jQueryExternal Data Access with jQuery
External Data Access with jQueryDoncho Minkov
 
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" DominoRob Bontekoe
 
Acceptance Testing with Webrat
Acceptance Testing with WebratAcceptance Testing with Webrat
Acceptance Testing with WebratLuismi Cavallé
 

Similar to 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
 

Recently uploaded

Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITmanoharjgpsolutions
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonApplitools
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdfAndrey Devyatkin
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jNeo4j
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...OnePlan Solutions
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolsosttopstonverter
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorTier1 app
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxRTS corp
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZABSYZ Inc
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...Bert Jan Schrijver
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptxVinzoCenzo
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingShane Coughlan
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Rob Geurden
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shardsChristopher Curtin
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecturerahul_net
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxAndreas Kunz
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLionel Briand
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 

Recently uploaded (20)

Best Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh ITBest Angular 17 Classroom & Online training - Naresh IT
Best Angular 17 Classroom & Online training - Naresh IT
 
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + KobitonLeveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
Leveraging AI for Mobile App Testing on Real Devices | Applitools + Kobiton
 
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
2024-04-09 - From Complexity to Clarity - AWS Summit AMS.pdf
 
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4jGraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
GraphSummit Madrid - Product Vision and Roadmap - Luis Salvador Neo4j
 
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
Revolutionizing the Digital Transformation Office - Leveraging OnePlan’s AI a...
 
eSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration toolseSoftTools IMAP Backup Software and migration tools
eSoftTools IMAP Backup Software and migration tools
 
Effectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryErrorEffectively Troubleshoot 9 Types of OutOfMemoryError
Effectively Troubleshoot 9 Types of OutOfMemoryError
 
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptxThe Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
The Role of IoT and Sensor Technology in Cargo Cloud Solutions.pptx
 
Salesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZSalesforce Implementation Services PPT By ABSYZ
Salesforce Implementation Services PPT By ABSYZ
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
JavaLand 2024 - Going serverless with Quarkus GraalVM native images and AWS L...
 
Osi security architecture in network.pptx
Osi security architecture in network.pptxOsi security architecture in network.pptx
Osi security architecture in network.pptx
 
Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full RecordingOpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
OpenChain Education Work Group Monthly Meeting - 2024-04-10 - Full Recording
 
Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...Simplifying Microservices & Apps - The art of effortless development - Meetup...
Simplifying Microservices & Apps - The art of effortless development - Meetup...
 
2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards2024 DevNexus Patterns for Resiliency: Shuffle shards
2024 DevNexus Patterns for Resiliency: Shuffle shards
 
Understanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM ArchitectureUnderstanding Flamingo - DeepMind's VLM Architecture
Understanding Flamingo - DeepMind's VLM Architecture
 
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptxUI5ers live - Custom Controls wrapping 3rd-party libs.pptx
UI5ers live - Custom Controls wrapping 3rd-party libs.pptx
 
Large Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and RepairLarge Language Models for Test Case Evolution and Repair
Large Language Models for Test Case Evolution and Repair
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 

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.') }) })