我正在尝试为 facebook api 使用 JS 接口(interface),这是我的第一个应用程序。 这是一个片段:
HTML:
<div id="fb-root"></div>
<script src="https://connect.facebook.net/ru_RU/all.js"></script>
<script type="text/javascript">facebook_init();</script>
JS:
function facebook_init() {
FB.init({
appId : '<MY APP ID IS HERE>',
channelUrl : '/media/channel.html', // Channel File
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
FB.api('/me', function(response) {
alert('Your name is ' + response.name);
});
}
channel .html:
<script src="https://connect.facebook.net/ru_RU/all.js"></script>
当我加载此页面时出现“您的姓名未定义”。 但是这段代码
FB.ui({ method: 'apprequests',
message: 'MSG',
title: 'TITLE'});
按预期工作。 请你帮助我好吗? 谢谢!
最佳答案
如果您通过 console.log(response)
记录您的 response
变量 you'll see what's wrong :
您将收到带有此消息的错误对象:
"An active access token must be used to query information about the current user."
因此,如果您想获取有关当前用户的信息,您还必须发送一个访问 token 。要获得有关此的更多信息,请查看 Facebook JS SDK页面。
关于Javascript FB.api - 未定义的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9218421/