2
votes

I am working on the API for a mobile application, which for the sake of argument is much like Foursquare and Instagram. Both of those applications will allow you to upload photos to your Facebook profile.

These will be added to a "Foursquare Photos" album, which will be made if it does not exist and you see it in your "Albums" area. Every time you add a new image it will become the album cover and you will see it displayed at the start of your album, so that images are in reverse chronological order (newest at the top/left, oldest bottom right).

To set the cover I assumed I could simply do this:

enter image description here

That is my attempt to post an update to the album ID, setting cover_photo as the photo ID of a file I've just uploaded. I have created the album fine, uploaded the photo fine all using the same access token - so we know it's not scopes (because yes I definitely have user_photos on the token).

A second approach was to assume this is automatic and try uploading a photo to the "start" of an album using the "position" field, but when I make a POST it seems to be completely ignored:

$photo = $facebook->api("/{$album_id}/photos", 'POST', array(
    'access_token' => $token->oauth_token, 
    'image' => '@'.$filename,
    'no_story' => 1, 
    'position' => 1,
    'from' => array(
        'id' => $user_opp->user->facebook_uid,
    ),
));

That uploads the image fine, but puts it at the end of the album, not the start.

So, how the f**k does this work? I've Googled my arse off and got nowhere. Tried the IRC and had no response, tried the Facebook Developer forums and they're down. I don't have any goats to sacrifice but maybe somebody out there knows.

1
I've had a suggestion that the position field being ignored by the POST method is probably a bug, so I have filed a bug report with Facebook developers.facebook.com/bugs/532976626728071 - Phil Sturgeon
In my experience, Facebook always uses the last photo in an album as the cover. Not intuitive, but it seems to be the case. - wuliwong
That is what is supposed to happen, but it doesn't. - Phil Sturgeon
Hmmm...we struggle with the fact that we send a batch of photos. So, although Facebook uses the last photo, it is impossible to predict 100% which photo will be last. :) - wuliwong

1 Answers

2
votes

Every time you add a new image it will become the album cover and you will see it displayed at the start of your album

That should happen automatically. And in my tests, it does.

A second approach was to assume this is automatic and try uploading a photo to the "start" of an album using the "position" field, but when I make a POST it seems to be completely ignored

That was never intended as a parameter for posting new photos, it was only returned when reading an albums photos from the API; and besides,

https://developers.facebook.com/roadmap/#october-2012

Removing position field for photos: The position field in both the photo FQL table as well as the Photo Graph API object will start returning 0 for all photos. The photos connection on an Album object in the Graph API will continue to return photos in the order they appear in the album.