# Using flickr API to download photo

**URL:** <https://rubytalk.org/t/using-flickr-api-to-download-photo/41888>\
**Category:** ruby-talk\
**Created:** [3 November 2007 07:13 UTC](https://rubytalk.org/t/using-flickr-api-to-download-photo/41888 "2007-11-03T07:13:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Chung-lin\_Wen](https://avatars.discourse-cdn.com/v4/letter/c/b5e925/32.png) [@Chung-lin\_Wen](https://rubytalk.org/u/Chung-lin_Wen)\
**Post date:** [3 November 2007 07:13 UTC](https://rubytalk.org/t/using-flickr-api-to-download-photo/41888/1 "2007-11-03T07:13:22Z")

</div>

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)  
> &nbsp;&nbsp;criteria = { 'tags' =\> 'landscape', 'page' =\> page\_iter.to\_s,  
> 'per\_page' =\> '500' }
> 
> &nbsp;&nbsp;for photo in flickr.photos( criteria )  
> &nbsp;&nbsp;&nbsp;&nbsp;File.open( photo.filename, 'w' ) do |file|  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.puts photo.file( 'Original' )  
> &nbsp;&nbsp;&nbsp;&nbsp;end  
> &nbsp;&nbsp;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)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /var/lib/gems/1.8/gems/flickr-1.0.0/./flickr.rb:322:in  
> `file'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:11  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:10:in `open'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:10  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:9:in `each'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:9  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:6:in `each'  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:6
> 
> =======================================
> 
> What's the problem?
> 
> Any idea?  
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Matt\_Foster](https://avatars.discourse-cdn.com/v4/letter/m/9de0a6/32.png) [@Matt\_Foster](https://rubytalk.org/u/Matt_Foster)\
**Post date:** [4 November 2007 12:14 UTC](https://rubytalk.org/t/using-flickr-api-to-download-photo/41888/2 "2007-11-04T12:14:17Z")

</div>

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/](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  
&nbsp;&nbsp;# Do stuff here  
end

Hope this helps,

Matt

> **···**
>
> On Nov 3, 2007 7:13 AM, Chung-lin Wen \<jonathan.clwen@gmail.com\> wrote:
> 
> > 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)  
> > &nbsp;&nbsp;criteria = { 'tags' =\> 'landscape', 'page' =\> page\_iter.to\_s,  
> > 'per\_page' =\> '500' }
> > 
> > &nbsp;&nbsp;for photo in flickr.photos( criteria )  
> > &nbsp;&nbsp;&nbsp;&nbsp;File.open( photo.filename, 'w' ) do |file|  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;file.puts photo.file( 'Original' )  
> > &nbsp;&nbsp;&nbsp;&nbsp;end  
> > &nbsp;&nbsp;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)  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /var/lib/gems/1.8/gems/flickr-1.0.0/./flickr.rb:322:in  
> > `file'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:11  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:10:in `open'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:10  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:9:in `each'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:9  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:6:in `each'  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from photosearch.rb:6
> > 
> > =======================================
> > 
> > What's the problem?
> 
> --  
> Grotesque but useful, like a chair made of antlers.  
> -- Thomas Harris - Red Dragon  
> Matt Foster | [http://my-mili.eu/matt](http://my-mili.eu/matt)
