iPhone Game Development - Chris Craft [81]
Start by creating a One Line Story template with the Feed Template Console. In the text box under the label One Line Story, enter the following example feed template:
{*actor*} just earned {*score*} points, and has achieved the rank of {*rank*} in Rochambeau.
This example feed template contains three template tokens: {*actor*}, {*score*}, and {*rank*}. The {*actor*} token is a special reserved Facebook template token. Facebook automatically replaces the {*actor*} token with the name of the currently logged-in Facebook user. You can see the final registered template bundle in Figure 6.15.
FIGURE 6.15
Registered template bundle on Facebook
The other tokens are replaced with the values provided from your application, as you will see later in this chapter. But you can supply the Feed Template Console with sample data. Enter the following text into the Sample Template Data field:
{“score”:”53324”, “rank”: “Captain”}
Click the Next button to test-run your feed template (Figure 6.16). When you are done testing your feed template, click the Next button again to proceed. You are given the option to Create a Short Story template. Short Story templates have a few more options than One Line Story templates. For one thing, you can use Facebook Markup Language (FBML) inside them. But for now you only need to use the One Line Story template, so click the Skip button.
Tip
Facebook Markup Language (FBML) enables you to build Facebook applications that deeply integrate into a user's Facebook experience. Learn more at http://wiki.developers.facebook.com/index.php/FBML.
FIGURE 6.16
The Feed Template Console's Template preview
You now have the option of creating an action link—a short string of text that accompanies a Feed story and invites the user to take some action related to that story. An action link is actually a hyperlink to a URL on Facebook, your Web site, or another third-party Web site. You can either skip this option or create an action link pointing to a URL of your choosing. For example, you might decide to create an action link that allows users to click their score and see a more complete high-score board with scores and ranks of other players.
When you're ready to review and register your feed template, click the Register Template Bundle button. You should now see a Template Bundle Registration Succeeded dialog box that presents you with your new template bundle ID.
You will need to update your publishFeed to use your new template bundle ID. Once you have done this, click the Build and Go button. You should then be able to navigate to the Publish Story screen (Figure 6.17). After you agree to allow the application to update your profile, you should see a new item on your Facebook page, which should look like Figure 6.18.
FIGURE 6.17
Publish Story screen
FIGURE 6.18
Facebook Wall update
It's your choice whether you use your Facebook application's Template Bundle section or the Feed Template Console Tool, but either one of these techniques lets you create a new feed template, which will be used by Facebook to publish messages from your application to each of your user's feeds. This is done through the publishFeed method located in the SessionViewController.m file:
- (void)publishFeed:(id)target
{
FBFeedDialog* dialog = [[[FBFeedDialog alloc] init] autorelease];
dialog.delegate = self;
dialog.templateBundleId = 0123456789;
dialog.templateData = @”{\”score\”: \”key1\”, \”rank\”: \”value1\”}”;
[dialog show];
}
Imagine if the example feed template had the template bundle ID of 0123456789 in Facebook, which would then match the template bundle ID being used in the publishFeed method. The following output would be generated by Facebook to be published on the currently logged-in user's feed. See if you can guess the produced output before reading ahead.
Apps Amuck just earned key1 points, and has achieved the rank of value1 in Rochambeau. Seeing this should help make what is happening