スクリプトリファレンスを一度インクルードし、ページがロードされたときにスクリプトでinitを呼び出すだけで済みます。これは、fb:likeボタンまたはログインスクリプトのいずれかに使用できます。
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'YOUR APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
これの鍵は、xfbmlをtrueに設定することです(#xfbml = 1と同じです)。あなたがそのセットを持っていないなら、そのようなボタンはレンダリングされません。
あなたがログインイベントをサブスクライブしたい場合はFB.init()呼び出しの後だけで次のスクリプトを追加します。
FB.Event.subscribe('auth.login', function(response) {
window.location.reload(); // or something else...
});
そして、ここでは、ログインスクリプトは、ユーザーがクリックしたときにのみ解雇されることであろうがリンク、ボタンなど
function doLogin() {
FB.login(function(response) {
if (response.session) {
if (response.perms) {
// user is logged in and granted some permissions.
// perms is a comma separated list of granted permissions
} else {
// user is logged in, but did not grant any permissions
}
} else {
// user is not logged in
}
}, {perms:'read_stream,publish_stream,offline_access'});
}
I _do_にはどちらか一方のみが含まれていますが、1つのバージョンを入れるともう一方のバージョンが中断されます。 – matthewdunnam