RSS Feeds for Photos With Multiple Tags in Flickr
There is an updated version of my script available!. Thanks Timtom!
In its RSS feeds, Flickr doesn't let you get photos tagged with all tags you tell it in an RSS feed, so I whipped up a script that, if you have your own server, creates RSS feeds of the tags you specify. If you called it 'multitags.php', and you put it on your site, say example.com, the URL would look something like http://www.example.com/multitags.php?tags=vancouver+seawall That would get you an RSS feed (in a format very similar to the format of the RSS feeds that Flickr outputs) of photos that are tagged with both 'vancouver' and 'seawall'.
If you used a comma instead of a plus, it looks for photos tagged with either of the tags, so http://www.example.com/multitags.php?tags=vancouver,seawall would get you photos tagged with 'vancouver' mixed in with the photos tagged with 'seawall'. There is a way to get RSS feeds of tags this way, but why figure that out. How to do it is in a forum somewhere, but I couldn't remember where, so I just coded that into the script.
You'll need two things to use the script: the excellent phpFlickr library (support for uploading coming, nice!) and a Flickr API key, which you can get at http://www.flickr.com/services/api/. You'll need to change the three variables at the top of the script, which follows, accordingly.
A note about the code: the first little bit about the XML declaration making up multiple lines is a workaround for the code dispaly. And yes, there are a lot of print statements. It makes it easier for me to debug.
It's probably best to keep the URL secret, so that the only person hitting the script is you. The RSS feeds work for me in NetNewsWire, but please do submit bug reports in the comments.
$php_flickr_cache = '/lib/phpflickr/cache';
$flickr_api_key = 'your Flickr API key here';
require_once($php_flickr_location . '/phpFlickr.php');
$f = new phpFlickr($flickr_api_key);
if (isset($php_flickr_cache)) {
$f-?>enableCache("fs", $php_flickr_cache);
}
if ($_GET && $_GET['tags']) {
$tags = urlencode($_GET['tags']);
$tag_mode = 'any';
if (strstr($tags, '+')) {
$tags = str_replace('+', ',', $tags);
$tag_mode = 'all';
}
else if (strstr($tags, "%2C")) {
$tags = str_replace('%2C', ',', $tags);
$tag_mode = 'any';
}
}
$photos = $f->photos_search(array('tags' => $tags, 'tag_mode' => $tag_mode, 'per_page' => '15'));
header("Content-type: text/xml");
$rss_feed = "
$rss_feed .= "?>\n";
$rss_feed .= "
$rss_feed .= "
$rss_feed .= "
$rss_feed .= str_replace(",", ' and ', $tags);
$rss_feed .= "
$rss_feed .= "
$requested_url = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
$rss_feed .= "
$requested_url\n";
$rss_feed .= "
\n";
foreach (
$photos['photo'] as $id) {
$u = $f->urls_getUserPhotos($id['owner']);
$rss_feed .= "
$link = $u . $id['id'] . "/";
$rss_feed .= "
$link\n";
$rss_feed .= "
$rss_feed .= "
$username_elements = explode("/", $u);
$username = $username_elements[4];
$rss_feed .= "<p><a href=\"$u\">$username</a> has posted a photo:</p>\n\n";
$rss_feed .= "<p><a href=\"$link\">";
$rss_feed .= "<img src=\"http://farm";
$rss_feed .= $id['farm'];
$rss_feed .= ".static.flickr.com/";
$rss_feed .= $id['server'];
$rss_feed .= '/';
$rss_feed .= $id['id'];
$rss_feed .= "_";
$rss_feed .= $id['secret'];
$rss_feed .= "_m.jpg";
$rss_feed .= "\" alt=\"". $id['title'] . "\" style=\"border: 1px solid #000000;\"/></a></p>";
$rss_feed .= "
$rss_feed .= "
$rss_feed .= $id['title'];
$rss_feed .= "
$rss_feed .= "
}
$rss_feed .= "
$rss_feed .= "
print $rss_feed;
?>
There is an updated version of my script available!. Thanks Timtom!
In its RSS feeds, Flickr doesn't let you get photos tagged with all tags you tell it in an RSS feed, so I whipped up a script that, if you have your own server, creates RSS feeds of the tags you specify. If you called it 'multitags.php', and you put it on your site, say example.com, the URL would look something like http://www.example.com/multitags.php?tags=vancouver+seawall That would get you an RSS feed (in a format very similar to the format of the RSS feeds that Flickr outputs) of photos that are tagged with both 'vancouver' and 'seawall'.
If you used a comma instead of a plus, it looks for photos tagged with either of the tags, so http://www.example.com/multitags.php?tags=vancouver,seawall would get you photos tagged with 'vancouver' mixed in with the photos tagged with 'seawall'. There is a way to get RSS feeds of tags this way, but why figure that out. How to do it is in a forum somewhere, but I couldn't remember where, so I just coded that into the script.
You'll need two things to use the script: the excellent phpFlickr library (support for uploading coming, nice!) and a Flickr API key, which you can get at http://www.flickr.com/services/api/. You'll need to change the three variables at the top of the script, which follows, accordingly.
Comments
Ed (not verified)
Tue, 2008-01-22 17:52
Permalink
I am getting a header issue.
Richard
Tue, 2008-01-22 22:41
Permalink
Ed and I talked in IM, and
Bilel (not verified)
Tue, 2008-02-19 20:58
Permalink
That's a great work
Keith Sloan (not verified)
Mon, 2008-05-19 04:56
Permalink
Well I get some results, but
Richard
Mon, 2008-05-19 20:02
Permalink
Looks like the script could
boem (not verified)
Thu, 2009-03-12 01:07
Permalink
Would it be possible to