我正在开发一个与facebook帐户集成的网站,以显示网站上facebook帐户的笔记。但是在调用FB.api方法后,我收到的响应是未定义的,我无法访问'response.data'中的数据。
测试
<body>
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
window.fbAsyncInit = function()
{
FB.init({appId: '12345678', status: true, cookie: true, xfbml: true});
FB.api (
'/pagename/notes',
function(response)
{
alert(response.data.length);
}
);
};
</script>
</body>
有谁知道我哪里出错了?任何帮助将不胜感激。
感谢。
答案 0 :(得分:4)
如果您在响应对象上使用console.log
,则会发现它包含“error
”属性,response.error.message
为“需要访问令牌才能使用function (response) {
if (response.hasOwnProperty("error")) {
alert("Error: " + response.error.message);
} else {
//Success!
}
}
请求此资源。“
您可以使用以下方法检查您的回复是否包含错误:
{{1}}
对于错误,可以在此处找到类似的问题:"An access token is required to request this resource" while accessing an album / photo with Facebook php sdk
答案 1 :(得分:0)
阅读笔记需要read_stream权限 - 您的代码看起来不像是先获得它。 https://developers.facebook.com/docs/authentication/permissions/