我有这个代码,我从facebook上的官方教程
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<div id="fb-root">sei qui</div>
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '173721946132851', // App ID from the app dashboard
channelUrl : '//www.ilmiobloggo.net/LOVECALCULATOR/index.php', // Channel file for x-domain comms
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
};
// 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'));
FB.api('/me', function(response) {
alert('Your name is ' + response.name);
});
</script>
</body>
</html>
但FB.api不工作,我不明白为什么,我可以帮助我。我试图获取Apache日志错误到我的房子托管,但没有。
答案 0 :(得分:0)
尝试放置
FB.api('/me', function(response) {
alert('Your name is ' + response.name);
});
下面的行
// Additional initialization code such as adding Event Listeners goes here
但高于
};
e.g
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '173721946132851', // App ID from the app dashboard
channelUrl : '//www.ilmiobloggo.net/LOVECALCULATOR/index.php', // Channel file for x-domain comms
status : true, // Check Facebook Login status
xfbml : true // Look for social plugins on the page
});
// Additional initialization code such as adding Event Listeners goes here
FB.api('/me', function(response) {
alert('Your name is ' + response.name);
});
};
你在创建FB之前调用FB.api。这也会产生JavaScript错误,可以在浏览器中找到。不在Apache日志中。尝试打开Chrome Developer工具/ firebug等并查看控制台。
最后一点,您没有任何代码可以让用户使用authorize您的应用。除非用户已授予访问您帐户的权限,否则FB.api('/ me')将不会返回正确的响应,因为它需要用户访问令牌