Javascript 发生FB.api()错误-FB未定义
我在尝试使用下面的代码在facebook上发布到墙上时出错。它有时可以在第一次登录后发布,但以后总是返回错误Javascript 发生FB.api()错误-FB未定义,javascript,facebook,Javascript,Facebook,我在尝试使用下面的代码在facebook上发布到墙上时出错。它有时可以在第一次登录后发布,但以后总是返回错误 <?php include_once "include/settings.php"; //include_once "include/messages.php"; if(isset($_GET["access_token"])) { $access_token = $_GET["access_token"]; } //$msg = $msg_en
<?php
include_once "include/settings.php";
//include_once "include/messages.php";
if(isset($_GET["access_token"]))
{
$access_token = $_GET["access_token"];
}
//$msg = $msg_en;
?>
<script language="javascript">
function publishToWall(){
var params = {};
params['message'] = 'message';
alert('<?php echo $access_token; ?>');
FB.api('/me/feed', 'post', { message: 'test' }, function(response) {
if (!response || response.error) {
alert('Error occured');
} else {
alert('Post ID: ' + response);
}
});
}
</script>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
<head>
<title></title>
<!--<link rel="stylesheet" href="css/style.css">-->
</head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
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
});
publishToWall();
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
</body>
</html>
函数publishToWall(){
var params={};
参数['message']='message';
警报(“”);
api('/me/feed',post',{message:'test'},函数(响应){
如果(!response | | response.error){
警报(“发生错误”);
}否则{
警报(“帖子ID:”+响应);
}
});
}
window.fbAsyninit=函数(){
FB.init({
appId:'您的应用程序ID',
状态:true,//检查登录状态
cookie:true,//启用cookie以允许服务器访问会话
xfbml:true//解析xfbml
});
publishToWall();
};
(功能(){
var e=document.createElement('script');
e、 src=document.location.protocol+'//connect.facebook.net/en_US/all.js';
e、 异步=真;
document.getElementById('fb-root').appendChild(e);
}());
为什么您的
标签在
标签之前?将其放入
或
您的应用程序是否有权在墙上张贴?是的,我已将该权限授予我的应用程序。我尝试了您的建议,但仍收到发生错误的警报。