Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API - get a photos album ID

I'm writing an application that uploads a photo to facebook. I'm not supplying an album ID so an album is created on behalf of my app.

My question is: how do I get the album ID the photo was uploaded to?

When I GET the the photo information the album isn't present in the JSON which was my hope.

like image 925
joseym Avatar asked May 16 '11 19:05

joseym


2 Answers

Jimmy Sawczuk's answer is close, but doesn't work because FQL Photo table columns aid and pid are Rest/FQL API ids, not Graph API ids.

Fortunately the object_id and album_object_id columns in this table are indexable (contrary to the documentation) so this should give you both Rest/FQL & Graph ids for the album:

select aid, album_object_id from photo where object_id = ${GRAPH_PHOTO_ID}

In general object_id fields in Rest/FQL API responses are Graph API id (except for photo notifications, where it's the Rest/FQL id).

Re HonkyHonk's answer: not all photo link urls have a set parameter; in this case I think you can find the Rest/FQL API photo id from its other parameters, and then use Rest/FQL API to get the album id:

  • For users with 32-bit user-ids: calculate (id << 32) | pid
    • eg for http://www.facebook.com/photo.php?pid=7518353&id=549683637 this gives 2360873244068853905
  • Otherwise concatenate id, _ and pid
    • eg for http://www.facebook.com/photo.php?pid=155052&id=100002937903251 this gives 100002937903251_155052

It would help a lot if Facebook could document something about the two types of ids. Also the Graph API Photo schema should include the album's Graph API id.

like image 74
Richard Barnett Avatar answered Sep 21 '22 12:09

Richard Barnett


This is the easy way to get it :

like image 37
ROLANDO Avatar answered Sep 21 '22 12:09

ROLANDO