Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [66]

By Root 748 0
as often as a weight of 400, not 800 times more often).

You can also have fb:random select more than one option by specifying a count of the number you’d like returned in the pick parameter. By default, fb:random will try to pick unique options (i.e., it won’t return the same option more than once), but you can override that by specifying false in the unique parameter:

You're cool!

You're awesome!

You're swell!

You're rad!

Note that specifying false won’t guarantee duplication, but it means you will occasionally get back duplicates.

Displaying Content to Specific Browsers


Problem


I need to display content to specific browsers in order to get around some rendering issues.

Solution


Use the fb:user-agent tag. The simplest form is:

Your browser has lots of rendering issues!

Discussion


You might want to use this tag for reasons other than browser idiosyncrasies, but that’s likely to be the main use. Every browser, crawler, indexer, etc. has a different “user-agent” string that represents the browser and company who make it. A few popular examples are given in Table 6-4.

Table 6-4. Some fun user-agent examples

User agent

Description

Googlebot/2.1 ( http://www.googlebot.com/bot.html)

Google crawler

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.4; en-US; rv:1.9b5) Gecko/2008032619 Firefox/3.0b5

Mozilla Firefox 3.0b5 on an Intel-based Mac running Mac OS X 10.4

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; bgft)

Microsoft Internet Explorer 7 on Windows XP

Opera/9.00 (Windows NT 5.1; U; de)

Opera 9 on Windows NT, running in German

Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_2; en-ca) AppleWebKit/525.13 (KHTML, like Gecko) version/3.1 Safari/525.13

Safari 3.1 on an Intel-based Mac running Mac OS X 10.5.2

For a full list of user agents, see the excellent http://www.user-agents.org, maintained by Andreas Staeding. You can also quickly find out the user agent for your browser by visiting http://www.whatsmyuseragent.com, which includes an excellent resource page about how to fake different user agents in your browser for testing purposes (http://whatsmyuseragent.com/SwitchingUserAgents.asp).

The tag supports include, exclude, and mixed modes, so you could also do:

You should download Firefox!

and:

Time to upgrade to Firefox 3!

Note that the tag does appear to be case-sensitive, so “firefox/3.0” and “Firefox/3.0” aren’t the same thing.

Displaying Your Application’s Name


Problem


I’d like a way to output my application’s name so that it will update automatically if I change it later. Also, I decided to put the word “message” in my application’s name and have now discovered that I can’t add it to things like my Mini-Feed and News stories, because Facebook won’t let me put that word in those places.

Solution and Discussion


Use the very simple fb:application-name tag, which will output your app’s current name as plain text. The simplest and only form is:

Formatting Relative Time


Problem


I want to display time formatted and converted to my users’ local time zones.

Solution


Use the fb:time tag. The simplest form is:

If that doesn’t look like a date and time to you, read on to the Discussion.

Discussion


The tricky part here is that you have to pass in t in what’s known as “epoch seconds,” or the number of seconds that have elapsed since the Unix Epoch, which was January 1, 1970. You think I’m making this up? You couldn’t make this stuff up! No one would believe you. (See http://en.wikipedia.org/wiki/Unix_epoch for more information on why we use this seemingly bizarre method of encoding a date and time.)

Return Main Page Previous Page Next Page

®Online Book Reader