Facebook Cookbook - Jay Goldman [91]
Now that we’ve told Facebook where to find a bunch of the useful meta information about the video (hence the “meta” class), our Share dialog gets a lot smarter (Figure 6-59).
Figure 6-59. Share dialog using the meta class
The fb:share-button tag supports audio, image, video, news, blog, and mult mediums, and it has a whole bunch of different types of information you can send into it. The full documentation can be found at http://www.facebook.com/share_partners.php, though make sure you click on the unobvious “How do I make sure the Share Preview works?” link at the bottom to expand the content you’re looking for.
Feed Forms: Publishing Feed Stories from FBML
Problem
I’d like to give my users the ability to publish Mini-Feed stories about themselves or about their friends by completing a form in my app.
Solution
To create a form through which users can publish stories to their own Mini-Feed, include an HTML form with the special fbtype attribute to signify that Facebook should use it as a Feed Form:
You can include any fields, content, and controls you’d like in the form. On submit, Facebook will send the form to the URL specified in the action, and will then take your JSON-formatted response back and use it to render a preview of a story. For the example just shown, your server-side feed_handler.php page could be as simple as:
{"method":"feedStory", "content":{
"next":"http://apps.facebook.com/myapp/somepage",
"feed":{
"template_id":"",
"template_data":{"status":""}}}}
Depending on what template 12345678901 contained, the story preview for this example might look like Figure 6-60.
Figure 6-60. Feed Form preview
Discussion
We aren’t, of course, setting the status in the previous example, though we could quite easily, as the next field in the JSON response tells Facebook where to send the user after he closes the preview box. By making that a page in your app that sets the status, you could make this example fully functional.
In addition to the feedStory outlined earlier, you can also create a multiFeedStory to give users the ability to publish into their friend’s Mini-Feeds as well. The principle is exactly the same as feedStory, but you need to include one of fb:multi-friend-selector, fb:multi-friend-input, or fb:friend-selector:
You’ll also need to modify your server-side handler so that it lists mutliFeedStory as the method:
{"method":"multiFeedStory", "content":{
"next":"http://apps.facebook.com/superdisconapping/",
"feed":{
"template_id":"",
"template_data":{}}}}
In this particular example, assuming a template like this:
{*actor*} took a nap with {*target*}.
we have no additional fields, so our template_data return is empty. Facebook will automatically provide the {*actor*} token based on the user who is publishing the story and the {*target*} token from the friends they selected.
Redirecting to a Different URL
Problem
I’d like to redirect users to a different URL from one of my Canvas pages.
Solution
Use the fb:redirect tag. The simplest (and only)