Saturday, April 19, 2014

Facebook share functionality

<html>
<head>
<script src="http://connect.facebook.net/en_US/all.js" type="text/javascript"></script>
<script type="text/javascript">
window.fbAsyncInit = function()
{
    FB.init({
        appId  : '420388744727086',
        status : true, // check login status
        cookie : true, // enable cookies to allow the server to access the session
        xfbml  : true , // parse XFBML
        oauth : true // Enable oauth authentication
    });


};

function post_on_wall()
{
    FB.login(function(response)
    {
        if (response.authResponse)
        {
            var opts = {
                message : "Hello",
                name : 'Post Title',
                link : 'www.postlink.com',
                description : 'post description',
                picture : 'http://2.gravatar.com/avatar/8a13ef9d2ad87de23c6962b216f8e9f4?s=128&amp;d=mm&amp;r=G'
            };

            FB.api('/me/feed', 'post', opts, function(response)
            {
                if (!response || response.error)
                {
                    alert('Posting error occured');
                }
                else
                {
                    alert('Success - Post ID: ' + response.id);
                }
            });
        }
        else
        {
            alert('Not logged in');
        }
    }, { scope : 'publish_stream' });
}
</script>
<div id="fb_div">
    <h3>Post to your Facebook wall:</h3> <br />
    <input type="button" value="Post on Wall" onClick="post_on_wall();" />
</div>
<div id="fb-root"></div>
</html>

No comments:

Post a Comment