Heroku のサンプル アプリで取得した、Facebook アプリで標準の Facebook Javascript コードを使用しています。よくわかりませんが、注意してサンプル アプリを変更し、便利な基本的なことを実行することができました。
私の理解では、このコードは何らかの方法で Facebook Javascript SDK をロードします。つまり、javascript コード ファイルをロードします。実際にロードしているファイルは何ですか?他の JavaScript コード ファイルをロードするようにロードできないのはなぜですか? 例えば:
<script type="text/javascript" src="/javascript/jquery-1.7.1.min.js"></script>
この非常に複雑なアプローチの欠点は、私がそれを理解できないことです。また、それを理解していないため、使用方法についての直感もありません。
ここにコード:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : '<?php echo AppInfo::appID(); ?>', // App ID
channelUrl : '//<?php echo $_SERVER["HTTP_HOST"]; ?>/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
});
// Listen to the auth.login which will be called when the user logs in
// using the Login button
FB.Event.subscribe('auth.login', function(response) {
// We want to reload the page now so PHP can read the cookie that the
// Javascript SDK sat. But we don't want to use
// window.location.reload() because if this is in a canvas there was a
// post made to this page and a reload will trigger a message to the
// user asking if they want to send data again.
window.location = window.location;
});
FB.Canvas.setAutoGrow();
};
// Load the SDK Asynchronously
(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/all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
</script>