views:

278

answers:

2

I'm building a site that allows users to sign in using their facebook account.

I want to cache nice big versions of the users profile pictures. I know that i'm not allowed to cache images for more than 24 hours so i'm going to re-fetch the images once every 24h.

I thought i could get the url of the image original like this:

$fb=new Facebook($key,$secret);
$query = "SELECT src_big FROM photo WHERE pid IN (SELECT cover_pid FROM album WHERE owner = ".$id." AND name = 'Profile Pictures')";
$imgurl = $fb->api_client->fql_query($query);

http://wiki.developers.facebook.com/index.php/Photo_(FQL)

But i get an exception saying "Requires user session". Why do i need a user session? Is there a workaround for this? How does other sites solve this?

If i have a user session it works for some users but not all. Why not?

+1  A: 

For when it sporadically works: Some users may have set privacy settings to disallow applications access to their profile pics.

Possibly some users might not have uploaded a profile pic.

Edit: From the (new)fb menus go to: Account > Privacy Settings > Applications and Websites > What you Share
(This page explains about how the user's privacy setting choices affect fb-enhanced websites)

In short the external website can only access what fb users have made available to 'Everyone'.

John K
Okay, do you know where on facebook you set that privacy setting? I can't find it.
Martin
I put an edit in the answer.
John K
+1  A: 

Rules on photo accessibility are detailed with the Photos.get API method.

Privacy Note: Photos are visible on the Facebook Platform only if the photo owner has authorized the calling application, or the photo owner has not turned off access to the Platform.

The Photos.get method is essentialy a wrapper for querying the Photo FQL table so it follows the same rules.

Consider asking users for the offline_access extended permission so you can query their own photos even when they're not online. You'll need to store their session key in your database and make queries with that, but it will mean you can pull down the photos of users who have authorised your application whenever you want.

Karl B

related questions