Question

I made a small app to FB that is using FB.ui to allow users to share it on their wall. I'd like the shared posts to show "Share" link next to "Comment" and "Like", like on any normal wall post.

Is there any way to do this with FB.ui?

Or is there some other method that would still allow me to define customized image, title, description etc. to the wall post?

My current code:

function share(name, description) {
        FB.ui({
            method: 'feed',
            name: name,
            picture: '/img/fb.png',
            link: url,
            caption: '',
            message: '',
            description: description
            }, function() {
            });
    }
Was it helpful?

Solution

it can be done with share_open_graph method. the code should look like this

FB.ui({
    method: 'share_open_graph',
    action_type: 'og.shares',
    action_properties: JSON.stringify({
        object : {
           'og:url': 'http://astahdziq.in/', // your url to share
           'og:title': 'Here my custom title',
           'og:description': 'here custom description',
           'og:image': 'http://example.com/link/to/your/image.jpg'
        }
    })
    },
    // callback
    function(response) {
    if (response && !response.error_message) {
        // then get post content
        alert('successfully posted. Status id : '+response.post_id);
    } else {
        alert('Something went error.');
    }
});

OTHER TIPS

For the share action,

FB.ui({
  method: 'share',
  href: 'https://developers.facebook.com/docs/',
}, function(response){});

To define customized image, title, description, use Open Graph Tags in the head of your page:

<meta property="og:url" content="http://samples.ogp.me/136756249803614" /> 
<meta property="og:title" content="Chocolate Pecan Pie" />
<meta property="og:description" content="This pie is delicious!" /> 
<meta property="og:image" content="https://fbcdn-dragon-a.akamaihd.net/hphotos-ak-prn1/851565_496755187057665_544240989_n.jpg" />

The effect would be:

enter image description here

You have to use the action property see the documentation here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top