FB.ui share set the title, message and image

This works for me as of 2018-01-01, using the share-open-graph method. This works, but seems to be magic, and undocumented, so caveat coder.

shareOnFB: function() {
    var img = "image.jpg";
    var desc = "your caption here";
    var title = 'your title here';
    var link = 'https://your.link.here/';

    // Open FB share popup
    FB.ui({
        method: 'share_open_graph',
        action_type: 'og.shares',
        action_properties: JSON.stringify({
            object: {
                'og:url': link,
                'og:title': title,
                'og:description': desc,
                'og:image': img
            }
        })
    },
    function (response) {
        // Action after response
    });

The meta data might be cached by Facebook. Try entering your url in the Facebook debugger: https://developers.facebook.com/tools/debug/

This will clear the cache.

For image use this:

<meta property="og:image" content="http://yourimage">

Facebook recommends using images with a min size of 1200x630 pixels


The code you are using is deprecated. You can use the following share dialogue with dynamically overridden attributes:

FB.ui({
  method: 'share_open_graph',
  action_type: 'og.shares',
  display: 'popup',
  action_properties: JSON.stringify({
    object: {
      'og:url': 'https://your-url-here.com',
      'og:title': 'Title to show',
      'og:description': 'The description',
      'og:image': 'https://path-to-image.png'
    }
  })
}, function(response) {
  // Action after response
});

For a detailed working example, checkout: http://drib.tech/programming/dynamically-change-facebook-open-graph-meta-data-javascript.

If you share a web page (having og meta tags) on Facebook and update the title and description etc later, they will not be get updated instantly on Facebook as it caches your web page and scrap the page again after 2 days.

So if you want to update the title, description etc on Facebook instantly, you'll need to Scrap the web page again using Facebook debug tool.


Facebook documentation says that "share" method has only href parameter, but I have found it is not true. You can use very similar parameters to the "feed" method. This is what I have used and works:

    FB.ui(
    {
        method: 'share',
        href: 'your_url',     // The same than link in feed method
        title: 'your_title',  // The same than name in feed method
        picture: 'path_to_your_picture',  
        caption: 'your_caption',  
        description: 'your_description',
     },
     function(response){
        // your code to manage the response
     });