An introduction to Facebook Graph API and OAuth 2. This presentation covers basic example of Facebook Graph API, and including how OAuth 2 client-side flow works.
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.
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
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
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
})
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>