O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required