After a successful implementation of my FlashStuf Facebook app, I went ahead and decifered the API to create an interface for the Publisher feature. I’ll cover the basic ideas here that will be pretty much universal across languages, but when I give code examples they’ll be in PHP.
First, the FlashStuf Publisher performs like this: a user wants to post a file from FlashStuf to his/her own profile or a friend’s. When they click “Share File” above the publisher, they are presented with a search box, a comment box, and the Post button which is only enabled upon selecting a file. Typing in a keyword will do a search, return the results to the publisher, and allow the user to select one. When posted, a feed story is published (as with all publisher actions). This is the kind of application I’ll be walking through (and you can see it in action here).
The Publisher interface is a little different from the Canvas page because it requires a JSON response, as opposed to plain HTML/FBML. On the FlashStuf Publisher, I simply compiled the markup into a single variable, $fbml, then used the following code to present the array of required data as JSON (get more information on the attributes on the New Design Publisher page of the Development Wiki):
$params = array('content' => array('fbml' => $fbml,
'publishEnabled' => false,
'commentEnabled' => true ),
'method' => 'publisher_getInterface'
);
echo json_encode($params);
Now that we have the interface, we need the user to be able to perform certain actions. This is a little more complicated than simply submitting a form or linking to a page in the site, as that exits the entire page– and we need information to instead fill the Publisher window. You can use AJAX here, as Facebook supports it, but I would highly recommend Mock AJAX, as it was the much faster and easier method to go about creating the publisher for me. This is what my search form looked like, including the form element to fill with search results.

<form id="search_form">Search for file: <input type="text" name="search" /></form>
<a clickrewriteurl="http://www.myapp.com/publisher_search.php" clickrewriteform="search_form" clickrewriteid="results_content" clicktoshow="spinner">Search</a>
<form id="results_content"><img src="http://www.myapp.com/img/working.gif" id="spinner" style="display:none;"/></form>
Note that the clickrewriteurl is the page that the parameters are sent to, the clickrewriteform is the form from which parameters are sent, and clickrewriteid is the element id which will be populated with the results. More information can be found on the Mock AJAX page. Also, it is important to note that the clickrewriteurl will send back plain HTML– just like regular AJAX. This is the result:

To enable the Post button once a selection was made, I used the FBJS setPublishStatus() method. Passing in true will enable the final stage: posting.
<input type="radio" name="file_id" value="125" onclick="Facebook.setPublishStatus(true);" />
Hopefully this is a good starting point. Next time, I’ll go into feed stories and how to post them using the Publisher.
Facebook Apps, Tutorials AJAX, facebook, FB Publisher, PHP