christof
christof

Reputation: 41

Facebook share with custom parameters with API version 2.9

I need to share a result of a quiz on Facebook containing a custom title, picture and description. Which worked perfectly before update to version 2.9 on April 18.

But it isn't working with Version 2.9. So am I missing out something there? Or does Facebook not want us to share custom Facebook Feeds of our websites in 2017?

For my Setup for a test Facebook feed I coded strictly with Facebook Developers Documentation.

Facebook Changelog v2.9 says parameter picture, name, description and caption are not supported anymore.

My Facebook API init:

<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '*APP-ID*',
      xfbml      : true,
      version    : 'v2.9'
    });
    FB.AppEvents.logPageView();
  };

  (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>

My fb-share call:

<script>
    $(document).ready(function() {
        $('#fbButton').click(function() {
            FB.ui({
                method: 'feed',
                link: '*URL*',
                caption: 'An example caption',
                picture: '*URL*/img/content4.jpg',
                name: 'An example name',
                description: 'An example description'
            }, function(response){});
        });
    });
</script>

As a result I get a Facebook feed without any picture or description. The only thing is a title (the title of page defined in the <head> with <title>).

Obviously, the usual procedure isn't working anymore.

So is there any way to share custom texts with custom pictures with the new Facebook API version 2.9?

Is there any workaround? Or is it just impossible with v2.9, because Facebook doesn't want us to share custom feeds like this? (for whatever reason..)

(and no, I cannot use og:tags)

Upvotes: 4

Views: 4966

Answers (3)

Vipul
Vipul

Reputation: 431

I just tried to use open graph method instead of feed and override og properties, see below:

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://apps.investis.com/Dharmendra/fbPOC/south.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.');
            }
        });

this worked for me as I am able to post custom image with title and description.

Upvotes: 3

andyrandy
andyrandy

Reputation: 73984

https://developers.facebook.com/docs/apps/changelog#v2_9

Custom parameters are not possible anymore, shared URLs only take their data from the Open Graph Tags on the website, Open Graph Tags need to be static for each URL. Else, you could share ANY URL with ANY title/description, which could be misleading.

Upvotes: 0

Ovidiu Turean
Ovidiu Turean

Reputation: 11

Just encounter with this problem myself. After some research I found this solution:

www.facebook.com/sharer.php?caption=[caption]&description=[description]&u=[website]&picture=[image-url]

you can use JavaScript window.open to simulate the behavior like this:

Here is a working example: https://jsfiddle.net/ovidiu_turean/mhuexvjL/

<button onclick="myFunction()">Try it</button>

<script>
function myFunction() {
  window.open('https://www.facebook.com/sharer.php?title=ThisIsAtitle&description=ThisIsAdesc&u=https://www.google.ro&picture=https://wallpapers.wallhaven.cc/wallpapers/full/wallhaven-526588.jpg', 'Share', 'scrollbars=yes,resizable=yes,toolbar=no,menubar=no,scrollbars=no,location=no,directories=no,width=300, height=300, top=300, left=300' );
}
</script>

Upvotes: 0

Related Questions