Flickr Coding: Updating Date Taken

The Problem

So, while working on photos for my online photo calendar, I’ve been using Flickr’s official online photo editor, Picnik. For basic edits, cropping, etc., Picnik has been working just fine for me. However, I noticed early on that whenever I edited a photo using Picnik, the finished product would have it’s Date Taken value reset to the current date instead of when I originally took it.

Maybe that wouldn’t matter to some people, but I prefer to keep good records. 🙂

For the photo calendar images, I knew I was okay because I was saving the edit photos as new images (mainly because they were resized to be square). This meant I had two copies of the same photo, the original with the correct Date Taken and the edited calendar version with the date of whenever I edited it. This meant all I had to do was somehow copy over the dates from the original photos back over to the modified versions. Easy enough.

The Solution

All I really had to do for this was to make two simple calls to the Flickr API, the first to get the original photo dates and the second to update the new photo. Pretty simple.

Step 1: Call flickr.photos.getInfo with the original photo id, which you can get from the URL of the photo page. For example, here’s the URL and original version of one of the photos.

Footsteps in the sand

http://www.flickr.com/photos/webnelly/2456401712/

In this example, the photo id is 2456401712. Once I have the photo id and call the getInfo method, I can retrieve the Date Taken value back from the response data and save that for the second call.

Step 2: Call to the flickr.photos.setDates method with the photo id of the edited photo and the Date Taken from the original photo. I already mentioned how I got the original Date Taken, and I can get the photo id of the edited photo from the photo page URL the same was as the original.

1117 - Nov 17th

http://www.flickr.com/photos/webnelly/3039946864/in/set-72157609319927215/

Here, the URL is a little longer because of the “in/set-{id}” part at the end, but that’s only because I saved all of the calendar photos in their own set. The photo id is still in the same place, and the one for this photo is 3039946864. Once I have that, I’m ready to call the setDates method.

Not Mentioned: The setDates method, as well as all the other update methods, require Write level permissions. Acquiring the necessary permissions is an entirely different discussion altogether, which I’m not going to cover here. Check out the API docs for more details.

Matching Up The Photos

Unfortunately, when you edit a photo using Picnik and save it as a new copy, there is no recorded link between the two of them. That means, despite being able to write code using the API to actually copy the dates over from one photo to another, I still had to manually track down the before and after photos.

That wasn’t terribly different for me because I had sort of planned ahead when editing these. I just mentioned that all the calendar (edited) photos are in their own Photoset, which keeps them in one place. For the original photos, I was tagging them as I was editing them, and used a tag dcal. I originally did this for purposes of not duplicating photos in the calendar, which you can imagine would be an easy mistake to make if you’re selecting 365 photos. It turned out to be just as helpful for this purpose as well.

So after I wrote and tested the code, the majority of the time was actually spent pairing up the before and after photos on Flickr, copying down their photo ids, and putting them into my little app. Worked like a charm.

This entry was posted in Flickr and tagged , .

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*