我正在创建一个用于测试 fb 登录的示例 html 文件。我使用了 facebook 开发人员页面中的代码,如下所示,但无法调用 FB.getLoginStatus。对于我的 facebook 应用程序设置,我有沙盒模式 NO 并放置一个随机站点 url:
<!DOCTYPE html>
<html>
<head>
<title>Example</title>
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : 'MYAPPID', // App ID from the App Dashboard
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
// Additional initialization code such as adding Event Listeners goes here
FB.getLoginStatus(function(stsResp) {
alert('get login status callback!');
});
};
// Load the SDK's source Asynchronously
(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));
</script>
</body>
</html>