janko-m edited this page Jun 3, 2012 · 11 revisions

Some tips

Tip #1

If you want sizes to be available to photos you're fetching from a set, it's not a good idea to call #get_sizes on each photo, because that will make an HTTP request on each photo, which can be very slow. Instead, when fetching photos from a set, pass in :include_sizes => true:

photos = Flickrie.photos_from_set(1242379, :include_sizes => true)
photo = photos.first
photo.source_url # => "http://farm8.staticflickr.com/7049/6946979188_25bb44852b_z.jpg"

Tip #2

When you get an access token, you can use it as long as you want. This is because Flickr uses the OAuth 1.0 protocol, and in that protocol access tokens last forever. And also, they are unique, so, every time you request for an access token from the same user, you will always get the same one. This is really cool, because the user has to authenticate only once, and you just have to store that access key somewhere (in the database, for example, if you're in a web application), and you can always reuse it.

Tip #3

You can also get a photo size in another way.

# These two lines do the same thing

# You also have the bang versions

# This is especially useful for the "symbol to proc" that Rails and newer versions of Ruby have
photos = Flickrie.photos_from_set(231848, :include_sizes => true)
photos.first.size # => "Medium 500"

Tip #4

You can override open_timeout and timeout like this:

Flickrie.open_timeout = 3
Flickrie.timeout = 4
  • open_timeout is the time (in seconds) to wait for the connection with Flickr to open (defaults to 4)
  • timeout is the time to wait for one block from Flickr's response to be read (defaults to 6)

If a timeout occurs, Faraday::Error::TimeoutError is raised.

If you're in a web application, this would go in an initializer.

Tip #5

There is a possibility that, when uploading a photo, an error is raised saying that the apropriate content type cannot be found for that photo. This can happen if the photo you were uploading has some rare extension, which means its content type also isn't well known.

If it happens, you can always pass in the content type manually:

Flickrie.upload("path/to/photo", :title => "Sebastian", :content_type => "CONTENT_TYPE")

Tip #6

If you need to have multiple authenticated users at the same time (for example, if you're writing a web application), you can do this by initializing Flickrie::Instance:

@john = Flickrie::Instance.new(johns_access_token, johns_access_secret)
@matthew = Flickrie::Instance.new(matthews_access_token, matthews_access_secret)

@matthew.upload "/path/to/photo.jpg"

Tip #7

In a web application, let's say you have this form:

<form action="/upload" method="post" enctype="multipart/form-data">
  <input type="file" name="file">
  <input type="submit">

And a user selects a file from his disk, and submits the form. When you handle the file upload, you can just pass in the file as the argument (instead of its path):


This currently works only in Rails and Sinatra, but you can also submit pull requests for other frameworks.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.