Created
June 1, 2017 12:57
-
-
Save mcarneiro/1b812ce6997aa9ee21fe257a60f83a2b to your computer and use it in GitHub Desktop.
Facebook login + getting image from feed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Test facebook feed</title> | |
<script> | |
window.getFeed = function() { | |
FB.api('/me/feed', function(response) { | |
console.log('me', response); | |
if (response.data[0]) { | |
console.log('post', response.data[0]); | |
FB.api('/' + response.data[0].id + '/attachments', function(response) { | |
console.log('attachments', response); | |
}); | |
} | |
}); | |
}; | |
window.checkLoginState = function() { | |
FB.getLoginStatus(function(response) { | |
console.log('login response', response); | |
getFeed(); | |
}); | |
}; | |
window.fbAsyncInit = function() { | |
FB.init({ | |
appId: '1321491577898611', | |
cookie: true, | |
xfbml: true, | |
version: 'v2.8' | |
}); | |
FB.AppEvents.logPageView(); | |
FB.getLoginStatus(function(response) { | |
console.log('get login response', response); | |
if (response.status === 'connected') { | |
console.log(response.authResponse.accessToken); | |
getFeed(); | |
} else { | |
FB.login(function(response) { | |
console.log('login response', response); | |
}, 'public_profile,email,user_posts,user_photos,user_friends'); | |
} | |
}); | |
}; | |
(function(d, s, id){ | |
var js, fjs = d.getElementsByTagName(s)[0]; | |
if (d.getElementById(id)) {return;} | |
js = d.createElement(s); js.id = id; | |
js.src = "//connect.facebook.net/en_US/sdk.js"; | |
fjs.parentNode.insertBefore(js, fjs); | |
}(document, 'script', 'facebook-jssdk')); | |
</script> | |
</head> | |
<body> | |
<fb:login-button scope="public_profile,email,user_posts,user_photos,user_friends" onlogin="checkLoginState();"> </fb:login-button> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Relevant links:
Create app on https://developers.facebook.com/apps (just follow the steps to create js)
Service and nodes reference: https://developers.facebook.com/docs/graph-api/reference
Permission list: https://developers.facebook.com/docs/facebook-login/permissions