Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [93]

By Root 778 0
book digitizing projects have identified as being impossible for Optical Character Recognition (OCR) software to understand. Every time you solve a reCAPTCHA, you’re helping a project to digitize two more words from our collected knowledge and history. For more information (including details about implementing reCAPTCHA on your own website), see http://www.repcatcha.net.

FBML Caching


Problem


I’d like to take advantage of Facebook’s FBML caching to store a block of FBML that I use often.

Solution


Use the fb:ref tag. There are two ways to use it, depending on how you’ve architected your app:

By handle

If you’re developing heavily in the Facebook API, this is probably the better method for you. Use the API call setRefHandle to initialize your handle:

$facebook->api_client->fbml_setRefHandle("MyUniqueAppHandle", "Some FBML Content");

Then insert the fb:ref tag in your FBML to pull the block out and display it:

Now when you want to update the content, just call setRefHandle again with new FBML and it will change everywhere you’ve put fb:ref tags.

By URL

If your app is based more on different files or pages on a server, you can still put FBML into the cache by giving it a unique URL. Create a page that only renders out the block you’d like stored, and then use the alternate form of the fb:ref tag:

When you want to change the content, update your page on your server and then make a simple API call to tell Facebook that it needs to reindex that URL:

$facebook->api_client->fbml.refreshRefUrl("http://www.someserver

.com/cacheThisPage.php")

Discussion


There are lots of places you might use this—really wherever you have a block of relatively static content you want to display—but the best use is probably for Profile Boxes that aren’t user-specific. In that case, you’ll want to pick one of the methods discussed earlier and then embed the fb:ref tag inside your call to profile.setFBML so that the Profiles all contain the ref. Once you do that, you can go ahead and update either your handle or your URL, and all of the Profiles will update automatically.

NOTE

You can retrieve an fb:ref using the FBML.setRefHandle() from the Facebook API. See Getting a (Ref) Handle on FBML for more information.

Analyzing Traffic with Google Analytics


Problem


I want to know more about what users are doing within my application, and I really love using Google Analytics on my off-Facebook site, but dropping its code into my Canvas page didn’t work. How can I use it?

Solution


Use the fb:google-analytics tag to insert your tracking code for you. The simplest form is:

where uacct is the _uacct variable from your Google-provided code block. The FBML parser will render that into:

Discussion


The first thing to note is that this tag still produces the old-style Analytics code that calls the urchinTracker(), rather than the new-style code:

One of the features of the new code is the automatic detection of HTTP versus HTTPS, which would be wasted inside of Facebook because there are no secure connections to Facebook apps at this time. It also offers you the ability to track specific events that you won’t be able to use, so try not to design your tracking and marketing strategies around any of the new features until the tag gets updated. You

Return Main Page Previous Page Next Page

®Online Book Reader