我正在使用FB Javascript SDK来检查用户是否喜欢我的页面。它适用于localhost
但是当我在服务器上传它时代码不起作用。我的代码如下:
<script>
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
});
FB.getLoginStatus(function(response) {
var page_id = "My Page ID";
if (response && response.authResponse) {
var user_id = response.authResponse.userID;
var fql_query = "SELECT uid FROM page_fan WHERE page_id = "+page_id+"and uid="+user_id;
FB.Data.query(fql_query).wait(function(rows) {
if (rows.length == 1 && rows[0].uid == user_id) {
alert('Liked');
} else {
alert('Not Liked');
}
});
}
});
};
// 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));
</script>
它适用于localhost
并显示警报但不显示在服务器上
答案 0 :(得分:2)
您需要将您的互联网域名添加到您的应用程序网站白名单。