- Create a Facebook Feed Template
- Publishing Stories
- Summary
Publishing Stories
After you've created your Facebook feed template, you can use it in your Facebook Connect application to publish stories to the user's newsfeed with the FB.Connect.showFeedDialog call. The showFeedDialog function takes the following parameters:
- The registered Template Bundle ID
- Array of token values
- Array of friends on whose wall the text should appear (optional, use null to skip it)
- Additional text for short and full stories (optional, use null to skip)
- Story size (no longer used, use null)
- The action to occur if the user has not yet authorized your Facebook application
The showFeedDialog function also accepts three optional parameters:
- A callback function to be executed after the showFeedDialog call completes (its completion is asynchronous, as it interacts with the user in a pop-up dialog).
- A label that appears at the top of the pop-up text box.
- Initial text that the user can write in the pop-up text box.
To demonstrate the publishing process, we'll extend our sample Facebook application described in the Introduction to Facebook Connect article with a simple chat board (view the source) that will publish messages to Facebook.
To demonstrate the publishing process, we'll extend our sample Facebook application, described in the earlier article "Use Facebook Connect to Bring Your Application to Millions of Users." For this example, we'll add a simple chat board (view the source) that will publish messages to Facebook.
The only interesting part of the chat board application is the fb_publish function, which calls the FB.Connect.showFeedDialog function:
function fb_publish(txt) { var fb_data = {"href":location.href}; FB.Connect.showFeedDialog(fb_template,fb_data, null, txt, null, FB.RequireConnect.promptConnect); }
The fb_publish function accepts a single parameter (the message the user has written), creates the array of token values, and calls the Facebook Connect function, which in turn shows the user the pop-up dialog shown in Figure 6.
After the user approves the story by clicking the Publish button, it automatically appears in her Facebook newsfeed (see Figure 7) and in the newsfeeds of all her friends.