2013-07-03 18 views
0

我有这样的代码,我已经从官方教程了在Facebook上测试API的Javascript工作不

<!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不工作,我不明白为什么,someoune能帮助我。我试图获得Apache日志错误到我的房屋托管,但没有。

回答

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开发人员工具/萤火虫等,并查看控制台。

最后一个注意事项,您没有任何用户的代码authorize您的应用程序。除非用户已授予访问您的帐户的权限,否则FB.api('/ me')不会返回您正确的响应,因为它需要用户访问令牌

+0

我已经完成了它,谢谢你,但现在我获得这个代码,名称是未定义的,我已经尝试过,也是Fireforx的插件,但没有,有一些想法? –

+0

您是否授予您应用权限,就像我在上一段中所说的那样。尝试添加'console.log(response);'之后你的警报,看到它打印出来的萤火虫 – TommyBs

+0

权限是好的,他们是user_about_meuser_likesuser_relationships,我有添加console.log(响应)但没有任何与FireBug的...我不明白... –