SlideShare une entreprise Scribd logo
1  sur  49
Télécharger pour lire hors ligne
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

Contenu connexe

Tendances

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
 

Tendances (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
 

En vedette

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
 

En vedette (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
 

Similaire à 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é
 

Similaire à 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
 

Dernier

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsJhone kinadey
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedDelhi Call girls
 
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) SolutionOnePlan Solutions
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...Jittipong Loespradit
 
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..pdfPearlKirahMaeRagusta1
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
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...kalichargn70th171
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...Nitya salvi
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456KiaraTiradoMicha
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024Mind IT Systems
 
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 WorkerThousandEyes
 
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.docxComplianceQuest1
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
+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
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfkalichargn70th171
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 

Dernier (20)

Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verifiedSector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
Sector 18, Noida Call girls :8448380779 Model Escorts | 100% verified
 
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
 
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
MarTech Trend 2024 Book : Marketing Technology Trends (2024 Edition) How Data...
 
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
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
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...
 
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...Chinsurah Escorts ☎️8617697112  Starting From 5K to 15K High Profile Escorts ...
Chinsurah Escorts ☎️8617697112 Starting From 5K to 15K High Profile Escorts ...
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
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
 
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
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
+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...
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdfPayment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
Payment Gateway Testing Simplified_ A Step-by-Step Guide for Beginners.pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

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