GithubHelp home page GithubHelp logo

dob / flickr_fu Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ayn/flickr_fu

2.0 3.0 2.0 190 KB

flickr-fu is a ruby interface around the flickr REST api

Home Page: http://www.commonthread.com/projects/flickr_fu/rdoc/

License: MIT License

Ruby 100.00%

flickr_fu's Introduction

= flickr-fu

== Contact

  Author: Ben Wyrosdick
  Email: ben [at] commonthread.com
  Lighthouse: http://commonthread.lighthouseapp.com/projects/12069-flickr_fu/overview
  Main Repository: http://github.com/commonthread/flickr_fu/tree/master

== Getting Started

  You need to first get an API key as detailed here:

  http://www.flickr.com/services/api/misc.api_keys.html
  
== Installation

  sudo gem install flickr-fu

== Documentation

  RDoc Documentation can be found here:

  http://www.commonthread.com/projects/flickr_fu/rdoc/

== Example flickr.yml
--- !map:HashWithIndifferentAccess
key: "YOUR KEY"
secret: "YOUR SECRET"
token_cache: "token_cache.yml"

== Authorization

  To authorise your application to access Flickr using your API key you will
  need to access a specific URL.
  
  To generate this URL run the following and when presented with the URL 
  access it from your browser. Confirm the application has permission at 
  the level you have specified.
  
  Note that flickr has different types of keys. If you use one for a webapplication,
  which is most likely, you need to define a callback and somehow make sure that
  you connect the parameter :frob that flickr send via the callback is assigned
  to the right user account. The best way to do this is to loop over all the current
  user's flickr accounts and try flickr.auth.token with the :frob.
  
  Finally, cache the token (this will create the token cache file)
  
  If you have an invalid API key you will see errors such as:
  
  "100: Invalid API Key"
  
  If you don't follow the process below to authorise your application
  you will see errors such as:
  
  "98: Login failed / Invalid auth token" or 
  "99: User not logged in / Insufficient permissions"
  
== Authorization Example for non-webapplication

  require 'flickr_fu'
  
  flickr = Flickr.new('flickr.yml')
  
  puts "visit the following url, then click <enter> once you have authorized:"

  # request write permissions
  puts flickr.auth.url(:write)
  
  gets
  
  flickr.auth.cache_token

== Authorization Example for a webapplication

  flickr.auth.token also contains the nsid and username, this
  example only stores the token and no other userdata.

  require 'flickr_fu'
  class FlickrController < ActionController::Base
    def create
      flickr = Flickr.new('flickr.yml')
      redirect_to flickr.auth.url(:write)
    end
    def flickr_callback
      flickr = Flickr.new('flickr.yml')
      flickr.auth.frob = params[:frob]
      current_user.update_attribute :flickr_token, flickr.auth.token.token
    end
    def something_else_with_flickr
      flickr = Flickr.new(YAML.load_file('flickr.yml').merge(:token => current_user.flickr_token))
      # now you have full access on the user's data :)
    end
  end

== Search Example

  require 'flickr_fu'

  flickr = Flickr.new('flickr.yml')

  photos = flickr.photos.search(:tags => 'ruby-flickr')

  puts "found #{photos.size} photo(s)"

  photos.each do |photo|
    puts photo.title
    puts photo.description unless [nil, ''].include?(photo.description)
    [:square, :thumbnail, :small, :medium, :large, :original].each do |size|
      puts "#{size}: #{photo.url(size)}"
    end
    puts "comments: #{photo.comments.size}"
    photo.comments.each do |comment|
      intro = "#{comment.author_name} says - "
      puts "#{intro}\"#{comment.comment.gsub("\n", "\n"+(" "*intro.length))}\""
    end
    puts "notes: #{photo.notes.size}"
    photo.notes.each do |note|
      puts "[#{note.x},#{note.y} ~ #{note.width}x#{note.height}] - \"#{note.note}\""
    end
    puts
    puts
  end
  
== Another Search Example

  If searching for photos by user id then you need to specify the 'alias' - without
  intervention this is usually set by Flickr and is an alphanumeric string. 
  
  To find out the user id for a given user, you can use the tool at:
  
  http://idgettr.com/
  
  And replace the line in the above sample to query on user id:
  
  photos = flickr.photos.search(:user_id => 'your_user_id_here')

== Patch Contributers

  Chris Ledet
  Maciej Biłas
  Mike Perham
  Chris Anderton
  Luke Francl
  Thomas R. Koll
  P. Mark Anderson
  Josh Nichols

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.