Facebook PhotoTag Tips

Anna • December 27, 2010 • Comments View Comments

Lately photo tagging is running rampant in the Facebook app world. In the few apps I’ve done using tagging, there was a sore lack of documentation. To remedy that, I thought I’d write up some of my learnings.

With photo-tagging, the data is labeled differently when read than when written. FYI- I’m using the PHP-SDK Api. So, from the read, tags are an array containing arrays. Here is a tag array of this photo from War and Peace:

"tags": {
      "data": [
       {
            "id": "4444332432432",
            "name": "Natasha Rostova",
            "x": 50,
            "y": 50,
            "created_time": "2010-12-27T21:24:42+0000"
         }
         {
            "id": "11999000022",
            "name": "Andrei Bolkonsky",
            "x": 20,
            "y": 50,
            "created_time": "2010-12-27T21:24:42+0000"
         }
      ]
   },

id: the user id identified in the photo.
x: the percentage from the left.
y: the percentage from the top.

To upload tag data, it’s very similar- you attach an array of tag data to the photo info in the argument array, with the key of “tags,” but the values are: x, y, and tag_uid. X and Y are the same, “tag_uid” is the user who will be tagged with this coordinate. Created_time is automatically added. Again, the coordinate isn’t the plotted absolute positions but the percentage from the width/height.
Example of creating a tagData array for upload, if you already had ($x,$y) coordinates:

$x_perc = round($x/$width,2)*100;
$y_perc = round($y/$height,2)*100;

$tagData[] = array(‘tag_uid’=>12323322, ‘x’=>$x_perc, ‘y’=>$y_perc);

Photo-tags base their x and y on the center of the image, so if you are matching an existing coordinate, remember to add half of the width and height to the original coordinate.

Facebook will hiccup if there are more than 20 photo-tags- to my knowledge the file still uploads but as “pending” and with an error. To be safe, we trim at 19. We sift through the array and manage the limit, killing any extra tags that come along.

Apps we’ve done with photo-tagging:
Christmas Tree Friends
Christmas Wreath Friends
Top Photos 2010

More reading:
- Open Graph Protocol
- Graph API Reference- Photo
- Old REST API for photo tagging
- Stack Overflow thread on problems with tagging

Category: Facebook, Tech, Techniques, phototagging

About the Author

I'm a developer with Momentus Media. I've done the gamut of OLAP DB modeling to iPhone development and Ruby on Rails. Now, I'm in the fast lane of rapid, viral app development on Facebook.

View Author Profile
blog comments powered by Disqus