我正在創建一個用於測試fb登錄的示例html文件。我使用了來自Facebook開發者頁面的代碼,如下所示,但無法調用FB.getLoginStatus。對於我的Facebook應用程序的設置,我有沙盒模式NO,把隨機網站網址:用於本地html文件的FB.getLoginStatus
<!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>
'// connect.facebook.net/en_US/all.js'是一個「協議相關」URL--它允許瀏覽器在請求資源時決定是使用HTTP還是HTTPS。但是,當您從文件系統進行測試時,如果沒有本地Web服務器,這當然不起作用。把'http:'放在它的前面以加載JS SDK。 – CBroe
感謝您的解釋讓sdk加載。現在它加載,但它的警報仍然不顯示。我也試圖把console.log寫入螢火蟲。但沒有運氣 – prostock
我不確定這是否工作在非HTTP設置。您應該設置一個本地Web服務器進行測試,這使事情變得更容易。 – CBroe