[英]See if user logged on to facebook
我正在嘗試使用facebook API查看用戶是否從我的網站登錄。
當我調用FB.getLoginStatus時,我沒有任何響應。 我嘗試了所有看到的示例代碼,但得到響應卻一無所獲。 有人可以幫我找出我的代碼存在的問題:
<div id="fb-root"></div>
<script type="text/javascript" src="//connect.facebook.net/en_US/all.js">
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : 'my_app_id', // App ID
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
};
// Load the SDK Asynchronously
(function(d){
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
}(document));
function GetFBLoginStatus() {
debugger;
window.fbAsyncInit()
alert("get status");
FB.getLoginStatus(function(response) {
alert("inside call back function");
if (response.status === 'connected') {
alert("logged in");
} else if (response.status === 'not_authorized') {
alert("not authorized");
} else {
alert("logged out");
}
return true;
}, true)
}
</script>
您的第一個腳本沒有結束標記:
<script type="text/javascript" src="//connect.facebook.net/en_US/all.js">
應該
<script type="text/javascript" src="//connect.facebook.net/en_US/all.js"></script>
現在,瀏覽器認為第二個腳本標簽是第一個腳本標簽中定義的腳本的一部分。 您會遇到解析錯誤,而其余的則不會執行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.