locked
Share on facebook page RRS feed

  • Question

  • Hi All,

    Now I am working on small project, there is a requirement to share their updates on facebook pages. I have written some code. that works fine for share on user wall, If I tried to share on page it fails. May I know, how to solve this problem.

    The code that I have written is below:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Share on Facebook </title>
    </head>
    <body>
    <script>
    window.fbAsyncInit = function () {
    FB.init({
    appId: 'Your_App_ID',
    xfbml: true,
    version: 'v2.1'
    });
    };
    function Share()
    {
    FB.login(function(response) {
    if (response.authResponse) {
    FB.api('/' + Your_Page_ID + '/feed', 'post',
    {
    'message': 'Your Message,
    'link': 'http://www.google.com/',

    name: 'Hi',

    'description': 'Hello World...!'

    },
    function(response) {
    if (response && !response.error)
    alert("Success:: " + response);
    else {
    alert("Error:: " + response);
    console.log(response);
    }
    });
    } else {
    console.log('User cancelled login or did not fully authorize.');
    }
    }, {
    scope: 'publish_actions,manage_pages',
    return_scopes: true
    });
    }
    (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/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
    } (document, 'script', 'facebook-jssdk'));
    </script>
    <input type="button" onclick="Share()" value="Share" />
    </body>
    </html>

    Thanks, In Advance.

    SuneelKumar Biyyapu.

    Wednesday, December 31, 2014 6:42 AM