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

Hiding Private Photos

Problem

How do I know whether I can show a photo to a user?

Solution

Use the fb:if-can-see-photo and specify a photo ID (pid). The simplest form is:

<fb:if-can-see-photo pid="12345">
    <fb:photo pid="12345" />
</fb:if-can-see-photo>

For more information on fb:photo, see Embedding Facebook Photos.

Discussion

The default behavior of fb:if-can-see-photo is to check for permission for loggedinuser, but you can specify a uid for a different user to check that person’s permissions instead. As always, you can include fb:else to display an alternate image:

<fb:if-can-see-photo pid="12345">
    <fb:photo pid="12345" />
    <fb:else>
        <img src="images/default.jpg" alt="Can't see this!" />
    </fb:else>
</fb:if-can-see-photo>

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