Online Book Reader

Home Category

Facebook Cookbook - Jay Goldman [65]

By Root 701 0
content only to users who have added my app or accepted the Terms of Service for my application?

Solution


Facebook used to offer two tags that provided an easy way to limit the visibility of content, but only one is still supported. The fb:if-user-has-added-app tag, which is now deprecated, worked for all users who had added your app. The fb:if-is-app-user tag, which you should now always use, limits the display to users who have explicitly accepted your Terms of Service. The simplest use case is:

Thanks for installing my application! You rock!

Discussion


With no uid specified, the tag will automatically assume that it’s for the current loggedinuser. You can specify a uid to check for a different user, as well as include the fb:else tag to provide alternate content:

Here's score: 55555!

hasn't signed up for this app!

Note that these tags can be used only in a Canvas page.

Displaying Content to Friends


Problem


How do I display content only to friends of a specific user?

Solution


Use the fb:if-is-friends-with-viewer tag. The simplest form is:

You're friends!

Discussion


As with all fb tags that begin with if, you can use the fb:else tag inside the fb:if-is-friends-with-viewer to provide alternate content if they aren’t friends. You can also specify a different uid if you don’t want to check for friendship with the loggedinuser, and you can explicitly exclude the loggedinuser if you don’t want to treat them as being friends with themselves (you will also be a friend of yourself unless you set includeself to false):

You're friends with . Yay!

You aren't friends with . Boo!

Displaying/Hiding Content to/from Specific Users


Problem


How do I display content only to a specific user?

Solution


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

You're it!

Discussion


As with all fb tags that begin with if, you can use the fb:else tag inside the fb:if-is-user to provide alternate content if the user isn’t the droid you’re looking for:

You're it!

You aren't it.

You might sometimes want to check for a bunch of different users you want to exclude from seeing some content. The tag supports comma-separated uids, and you can use the fb:else tag to actually do the inverse of the example just shown:

Everyone else sees this bit here.

Displaying Random Content


Problem


I’d like to display some content on my Canvas page, randomly selected from a few different options.

Solution


The fb:random and nested fb:random-option tags are the answer. The simplest form is:

You're cool!

You're awesome!

Discussion


Profile Boxes are a really great use of the fb:random tag, which gives you the ability to have different content appear each time the page refreshes, even though Profile Box content isn’t really dynamic.

You can assign weighting to the different options if there’s something you’d like shown more often than the other options:

A: This will be shown twice as often as B

B: This will be show half as often as A

The weights can be any number greater than zero, and they are relative to each other rather than being relative to a fixed starting point (so a weight of 800 will still be shown twice

Return Main Page Previous Page Next Page

®Online Book Reader