[英]FB.api is not a function
我正在尝试将所有帖子拉到用户墙上。 我运行了一个可以连接到FB的示例,但是当我尝试使用FB.api来获取用户名时(我肯定已成功连接),我得到FB.api is not a function
。 一些搜索发现这表明我使用了错误的API链接,但是当我尝试使用新的 API链接(似乎使用相同的方法进行连接)时,所有萤火虫NET面板均表示加载成功,没有任何错误。 。 。 什么都没有发生。
这是代码(将http://connect.facebook.net/en_US/all.js链接替换为http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js。 PHP的代码工作,直到我提到的错误):
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<script type="text/javascript">
function grab(){
FB.api('/me', function(response) {
alert(response.name);
});
}
function update_user_box() {
var user_box = document.getElementById("user");
user_box.innerHTML =
"<div>"
+ "<fb:profile-pic uid='loggedinuser' facebook-logo='true'></fb:profile-pic>"
+ " Welcome, <fb:name uid='loggedinuser' useyou='false'></fb:name>"
+ "</div>"
+ "<a href=\"javascript:grab()\">try me</a>";
FB.XFBML.Host.parseDomTree();
}
</script>
</head>
<body>
<div id='user'><fb:login-button onlogin="update_user_box();"></fb:login-button></div>
<br><br>
<div id="fb-root"></div>
<script type="text/javascript">
FB.init("b07e858317c9069d450023b7500b4511", "xd_receiver.htm", {"ifUserConnected": update_user_box});
</script>
</body>
</html>
感谢您提供的所有帮助!
我想您没有正确初始化。 我有类似的问题...我不清楚哪个是oAuth2.0,哪个是FB-Connect。 这似乎令人困惑。 我遵循了下面的示例,它对我有用。 看这里
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js"></script>
<script>
FB.init({
appId : 'YOUR APP ID',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true // parse XFBML
});
</script>
希望这可以帮助。
附带说明,您可能需要扩展权限才能访问publish_stream和read_stream。 你应该参考这里
Typeoneerror是正确的,您正在混合使用SDK。
这是我使用event.subscribe初始化较新的JS SDK的方式,以确保SDK已初始化并且用户已在JS端进行了身份验证,然后再继续进行任何API调用或让我的游戏尝试加载等。
<div id="fb-root"> </div>
<script>
window.fbAsyncInit = function() {
FB.init({appId: 'YOUR_APP_ID', status: true, cookie: true, xfbml: true});
FB.Canvas.setSize({ width: 760, height: 1000 }); // use this to increase canvas height
FB.Event.subscribe('auth.login', function(response) {
// You can call your function that requires FB.whatever here...
});
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
我还使用PHP SDK进行初始身份验证...如果未对用户进行身份验证,则将JS重定向回显到我们的登录URL(可从PHP SDK方法getLoginUrl获得)。 希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.