下面的代码完美运行.. 单击 fb:login 按钮时,它会将消息发布到已登录人的 facebook 墙上。
但是,我希望这在页面加载后立即发生,而不是在单击按钮后发生。如果用户已经登录,则该消息应张贴在墙上。我怎样才能做到这一点 ?
<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#appId=XXXXXXXXXXXXXXX&xfbml=1"></script>
<fb:login-button show-faces="false" width="200" max-rows="1" perms="publish_stream" onlogin="postonwall()">Click to Publish Below Content</fb:login-button>
<script>
function postonwall()
{
FB.api('/me/feed', 'post',
{
message: 'A good reference for APIs',
link: window.location.href,
name:'API Reference',
picture:'http://www.demo.lookmywebpage.com/publish-on-facebook-wall/Google-Twitter-Facebook.jpg',
description:'Demo Facebook Post'
}, function(response) {
if (!response || response.error) {
alert('Oops! User Denied Access');
} else {
alert('Success: Content Published');
}
});
}
</script>