Navigating through Facebook's documentation feels like trying to cross a crowded highway blindfolded. I have set up their Javascript SDK like this:
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '597118477106840',
xfbml : true,
version : 'v2.5'
});
};
(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>
I have created my own custom share button:
<button class="ui facebook button">Share</button>
Now, the question is what action to take upon clicking.
Facebook's examples are quite confusing. Their first example:
FB.ui({
method: 'share',
href: 'https://developers.facebook.com/docs/',
}, function(response){});
Right below this code snippet, they mention:
Include open graph meta tags on the page at this URL to customize the story that is shared back to Facebook.
So I added these meta tags:
<meta property="og:url" content="my-page.com" />
<meta property="og:type" content="article" />
<meta property="og:title" content="I really dislike Facebook's documentation" />
<meta property="og:description" content="Additional text?" />
<meta property="og:image" content="image.jpg" />
However, this approach doesn't seem to work as expected. The sharing still uses the default image and text. Continuing to read, I found this statement:
Trigger a Share Dialog using the FB.ui function with the share_open_graph method parameter to share an Open Graph story.
Although it contradicts the previous information, let's give it a try. Here is the code snippet provided:
FB.ui({
method: 'share_open_graph',
action_type: 'og.likes',
action_properties: JSON.stringify({
object:'https://developers.facebook.com/docs/',
})
}, function(response){});
Upon changing the object
to my webpage URL, various errors occur each time. Issues range from og:title
not being recognized as a string to attempted likes or shares with incorrect image and text. It appears there are multiple errors in this process.
What exactly is og.likes
? Facebook provides no list of other available action_types
or action_properties
, leaving users confused. They mention:
A string specifying which Open Graph action type to publish, e.g., og.likes for the built-in like type.
It should be noted that this example pertains to SHARING content, not liking it. This raises more questions about the correct procedure.
How can I achieve this correctly?