Marko Anastasov wrote this on May 13, 2010

Using Flickr API with Ruby and r2flickr

If you want to use Flickr API with Ruby, there are plenty of options. The one we’ve been using for a long time was rflickr by Trevor Schroeder, which is an implementation that matches the Flickr API as it is officially documented. However, it was unmaintained in RubyForge’s svn repo, and it needed some fixes, so we eventually published r2flickr. You can install it as a regular gem:

sudo gem install r2flickr

Here’s a hint on how you can search for photos with a certain tag and get some information about each of them:

flickr = Flickr.new(FLICKR_CACHE_PATH, FLICKR_API_KEY, FLICKR_SHARED_SECRET)

photos = flickr.photos.search(
  :tags => "sunrise",
  :per_page => 20, :page => 1,
  :sort => "date-posted-desc"
)

photos.each do |photo|
  info = photo.flickr.photos.getInfo(photo.id)
  puts "#{info.title} from #{info.ownername}"
  puts photo.url('t')
end

For more details, check out the project on GitHub.

comments powered by Disqus

About Marko Anastasov

Rendered Text co-founder. Started with code, currently more focused on people and words. Foosball striker and entry-level cyclist.

Suggested Reads

Rails Testing Handbook

A new ebook on building test-driven Rails apps with RSpec and Cucumber.

At Rendered Text, we have a long history with Ruby on Rails. Checking the blog archive reminds me that we published first posts about working with Rails way back in 2009.

———

Rendered Text is a software company. For questions regarding Semaphore, please visit semaphoreci.com. Otherwise, feel free to get in touch any time by sending us an email.