Skip to content

Instantly share code, notes, and snippets.

@hachi-eiji
Created December 24, 2012 16:03
Show Gist options
  • Save hachi-eiji/4369762 to your computer and use it in GitHub Desktop.
Save hachi-eiji/4369762 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">
<body>
<div id="fb-root"></div>
<button onClick="loginuser()">login</button>
<div id="user-info"></div>
<img src="xxxxxx">
</body>
</html>
<input type="text" id="memo">
<button onClick="postFeed()">postFeed</button>
<script>
function postFeed(){
var obj = {
method: 'feed',
redirect_uri: 'http://localhost/feed.html',
link: 'xxxxx',
picture:'oooooooo',
caption:'test',
description:'testtest'
};
FB.ui(obj, function(response){
console.log(response);
});
}
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
window.fbAsyncInit = function(){
FB.init({
appId : 'ooooooo', // App ID
channelUrl : '//localhost/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.Event.subscribe('auth.statusChange', handleStatusChange);
}
function loginuser(){
FB.login(function(response){
console.log(response);
}, {scope: 'publish_actions'});
}
function handleStatusChange(response) {
console.log(response.authResponse);
document.body.className = response.authResponse ? 'connected' : 'not_connected';
if (response.authResponse) {
console.log(response);
updateUserInfo(response);
}
}
function updateUserInfo(response) {
FB.api('/me', function(response) {
console.log(response);
document.getElementById('user-info').innerHTML = '<img src="https://graph.facebook.com/' + response.id + '/picture">' + response.name;
});
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment