Christian Heilmann

Small change in the flickr API output breaking my bad code

Wednesday, December 31st, 2008 at 12:23 pm

During my absence I got an email that the first version of my unobtrusive Flickr badge has stopped working. The reason was that Flickr changed the output of the API. I the old version the JSON object contained an HTML description that was run through htmlspecialchars() first. I always considered this a bit of a nuisance and wondered about the reason. Now the Flickr feed does not have the encoding any longer as you can see for example in the JSON output of my latest photos:


{

“title”: “Terminal 5 animated discs thingamabob *”,
“link”: “http://www.flickr.com/photos/codepo8/3141566868/”,
“media”: {m“},
“date_taken”: “2008-12-27T08:10:35-08:00”,
“description”: “

codepo8 posted a video:

Terminal 5 animated discs thingamabob *

* technical term, really

“,
“published”: “2008-12-27T16:10:35Z”,
“author”: “nobody@flickr.com (codepo8)”,
“author_id”: “11414938@N00”,
“tags”: “london art heathrow awesome animation t5 ba britishairways terminal5”
},

Before the change this would have been:


{

“title”: “Terminal 5 animated discs thingamabob *”,
“link”: “http://www.flickr.com/photos/codepo8/3141566868/”,
“media”: {m“},
“date_taken”: “2008-12-27T08:10:35-08:00”,
“description”: “

codepo8 posted a video:

"Terminal

* technical term, really

“,
“published”: “2008-12-27T16:10:35Z”,
“author”: “nobody@flickr.com (codepo8)”,
“author_id”: “11414938@N00”,
“tags”: “london art heathrow awesome animation t5 ba britishairways terminal5”
},

This broke my code as I was relying on regular expressions to get the photos. Taught me a lesson, and as we have a media property now there is no need for this any longer. The fix for the badge code was:


// buggy, bad
temp=obj.items[i].description.match(/src="([^&]*)"/)[1];”
// works :)
temp=obj.items[i].media.m;

Lesson learned: Don’t trust regular expressions and data scraping.

Thanks to Jennifer Forman Orth for flagging this up!

Tags: , , , , ,

Share on Mastodon (needs instance)

Share on Twitter

Newsletter

Check out the Dev Digest Newsletter I write every week for WeAreDevelopers. Latest issues:

Dev Digest 146: 🥱 React fatigue 📊 Query anything with SQL 🧠 AI News

Why it may not be needed to learn React, why Deepfake masks will be a big problem and your spirit animal in body fat! 

Dev Digest 147: Free Copilot! Panel: AI and devs! RTO is bad! Pi plays!

Free Copilot! Experts discuss what AI means for devs. Don't trust containers. Mandated RTO means brain drain. And Pi plays Pokemon!

Dev Digest 148: Behind the scenes of Dev Digest & end of the year reports.

In 50 editions of Dev Digest we gave you 2081 resources. Join us in looking back and learn about all the trends this year.

Dev Digest 149: Wordpress break, VW tracking leak, ChatGPT vs Google.

Slowly starting 2025 we look at ChatGPT vs Google, Copilot vs. Cursor and the state of AI crawlers to replace web search…

Dev Digest 150: Shifting manually to AI.

Manual coding is becoming less of a skill. How can we ensure the quality of generated code? Also, unpacking an APK can get you an AI model.

My other work: