Using flickr API to download photo

J

jonathan.clwen

I have wrote a small script to download flickr photo by tags, as the
following

=======================================

require 'rubygems'
require 'flickr'

flickr = Flickr.new

for page_iter in (1..100)
criteria = { 'tags' => 'landscape', 'page' => page_iter.to_s,
'per_page' => '500' }

for photo in flickr.photos( criteria )
File.open( photo.filename, 'w' ) do |file|
file.puts photo.file( 'Original' )
end
end
end

=======================================

I can download about the first 25 ~ 30 photos

and I get the following error message, then the program terminated:

=======================================

/var/lib/gems/1.8/gems/flickr-1.0.0/./flickr.rb:317:in `source':
undefined method `[]' for nil:NilClass (NoMethodError)
from /var/lib/gems/1.8/gems/flickr-1.0.0/./flickr.rb:322:in
`file'
from photosearch.rb:11
from photosearch.rb:10:in `open'
from photosearch.rb:10
from photosearch.rb:9:in `each'
from photosearch.rb:9
from photosearch.rb:6:in `each'
from photosearch.rb:6

=======================================

What's the problem?

Any idea?
 
M

mattfoster

I have wrote a small script to download flickr photo by tags, as the
following

=======================================

require 'rubygems'
require 'flickr'

flickr = Flickr.new

for page_iter in (1..100)
criteria = { 'tags' => 'landscape', 'page' => page_iter.to_s,
'per_page' => '500' }

for photo in flickr.photos( criteria )
File.open( photo.filename, 'w' ) do |file|
file.puts photo.file( 'Original' )
end
end
end

=======================================

I can download about the first 25 ~ 30 photos

and I get the following error message, then the program terminated:

=======================================

/var/lib/gems/1.8/gems/flickr-1.0.0/./flickr.rb:317:in `source':
undefined method `[]' for nil:NilClass (NoMethodError)
from /var/lib/gems/1.8/gems/flickr-1.0.0/./flickr.rb:322:in
`file'
from photosearch.rb:11
from photosearch.rb:10:in `open'
from photosearch.rb:10
from photosearch.rb:9:in `each'
from photosearch.rb:9
from photosearch.rb:6:in `each'
from photosearch.rb:6

=======================================

What's the problem?

Hi,

You probably don't have permission to download the photo in its
original size. Lots of flickr users don't allow it.

I ended up using flickraw: http://raa.ruby-lang.org/project/flickraw/
instead of flickr, where you can say things like:

perms = flickr.photos.getPerms:)photo_id => photo.id)
if perms.ispublic == 1
# Do stuff here
end

Hope this helps,

Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,056
Latest member
GlycogenSupporthealth

Latest Threads

Top