-1

The below code works perfectly.. On clicking the fb:login-button, it posts the message on facebook wall of the person who has logged in.

But, i want this to happen immediately after the page loads and not after clicking the button. If the user is logged In already, the message should be posted on wall. How can i do this ?

<div id="fb-root"></div>
<script src="http://connect.facebook.net/en_US/all.js#appId=XXXXXXXXXXXXXXX&amp;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>
Anuya
  • 8,082
  • 49
  • 137
  • 222

1 Answers1

0

But, i want this to happen immediately after the page loads and not after clicking the button.

So you want to annoy your users …?

If the user is logged In already, the message should be posted on wall. How can i do this ?

Use FB.getLoginStatus, and if the user is already connected, then make the post.

CBroe
  • 91,630
  • 14
  • 92
  • 150