每当我尝试添加我的记录变量时,它都不会运行postToFeed函数,试图解决这个问题几天没有任何帮助会很棒!
<div id='fb-root'></div>
<script src='http://connect.facebook.net/en_US/all.js'></script>
<p><a onclick='postToFeed(); return false;'>Post to Feed</a></p>
<p id='msg'></p>
<script>
FB.init({appId: "XXXXXXXXXXXX", status: true, cookie: true});
function postToFeed() {
// calling the API ...
var obj = {
method: 'feed',
link: 'https://google.com',
picture: 'http://google.com/logo.png',
name: 'gamehighscore',
caption: 'I just got a highscore of'+record+'',
description: 'Try to beat my score!.'
};
function callback(response) {
document.getElementById('msg').innerHTML = "Post ID: " + response['post_id'];
}
FB.ui(obj, callback);
}
</script>
答案 0 :(得分:0)
我想,在哪里:
FB.init({appId:“XXXXXXXXXXXX”,状态:true,cookie:true});
尚未加载FB javascript API。您需要以这种方式加载JavaScript API:
window.fbAsyncInit = function() {
FB.init({
appId: 'XXXXXXXXXX',
status: true,
cookie: true,
xfbml: true
});
或者这样:
<div id="fb-root"></div>
<script>(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#xfbml=1&appId=XXXXXXXX";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>