Created
April 23, 2012 14:06
-
-
Save maeharin/2471095 to your computer and use it in GitHub Desktop.
show facebook user's basic information (javascript/jQuery)
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
<html lang="ja"> | |
<head> | |
<script src="http://connect.facebook.net/ja_JP/all.js"></script> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> | |
</head> | |
<body> | |
<div id="start_section"></div> | |
<div id="friend_section"></div> | |
<div id="fb-root"></div> | |
<script type="text/javascript"> | |
/** | |
* facebookの認証制御 | |
*/ | |
function authFacebookAccount(){ | |
FB.getLoginStatus(function (response) { | |
if (response.status === 'connected') { | |
getMyinfo(); | |
} else if (response.status === 'not_authorized') { | |
FB.login(function (response) { | |
getMyinfo(); | |
}); | |
} else { | |
FB.login(function (response) { | |
alert('ログインしました。STARTボタンを押してください'); | |
}); | |
} | |
}); | |
} | |
/** | |
* ユーザー自身の情報を取得 | |
*/ | |
function getMyinfo() { | |
FB.api('/me', function (response) { | |
var additional_html; | |
for(var i in response) { | |
additional_html += i + ':' + response[i] + '<br>'; | |
} | |
$("#friend_section").html(additional_html); | |
}); | |
} | |
$(function(){ | |
var APP_ID = 'xxx'; //your app id | |
FB.init({ | |
appId: APP_ID, | |
status: true, | |
cookie: true, | |
xfbml: true, | |
oauth: true | |
}); | |
FB.getLoginStatus(function (response) { | |
$("#start_section").html('<button id="start">スタート</button>'); | |
$("#start").click(function(){ | |
authFacebookAccount(); | |
}); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment