O'Reilly logo

Facebook Cookbook by Jay Goldman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Displaying Content to App Users

Problem

How do I display 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:

<fb:if-is-app-user>Thanks for installing my application! You rock!</fb:if-is-app-user>

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:

<fb:if-is-app-user uid="12345">
    Here's <fb:name uid="12345" possessive="true" /> score: 55555!
    <fb:else>
        <fb:name uid="12345" /> hasn't signed up for this app!
    </fb:else>
</fb:if-is-app-user>

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

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required