Facebook Share Buttons

Problem

I’d like to include a Facebook Share button in my app to encourage my users to share items on their Profile or to send them to friends.

Solution

Use the fb:share-button tag. The simplest form is:

<fb:share-button class="url" href="http://apps.facebook.com/myapp/somePage.php" />

That will give you the standard Share button, shown in Figure 6-57.

Facebook Share button

Figure 6-57. Facebook Share button

Clicking on the button shows the Share dialog, with a choice between sending a message or posting to your Profile, as shown in Figure 6-58.

Share dialog

Figure 6-58. Share dialog

If your URL includes content and images, your users will have the option of selecting what they would like to include in the message or post.

Discussion

There are two modes (or “classes”) for the Share button: URL and meta. The URL class is easier and can be either an on- or off-Facebook URL, as seen earlier in this recipe. Meta class requires a little more effort on your behalf, but it also gives you more control over what appears in the Share dialog and in the message or Profile post. As an example, let’s say that you wanted to include a Facebook Share button to this great video of my friend Leo Laporte interviewing my friend Kris Krug (of Raincity Studios) on the Lab with Leo show, talking about this shiny new social network ...

Get Facebook Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.