Displaying Photos from Flickr Using XML-RPC:
Flickr is primarily a photo-sharing service provided by Yahoo!, though it has recently branched out to offer other features. Basic accounts are free, and Flickr has a web service API that provides access via REST, SOAP, and XML-RPC. Because we've already covered SOAP and REST, we'll build our client using the XML-RPC architecture.
As you probably expected, you need a Flickr key before you can access their API. Since Flickr is a part of Yahoo!, you must set up a Yahoo! account first, then associate that account with the Flickr service. Start at http://www.flickr.com/signup, which walks you through the sign-up process. Once you've got your Flickr key, you're ready to start building your XML-RPC client.
To make an XML-RPC client for your Rails application you need to:
Create an RPC driver
Call the methods
Use the results in your Rails application
We'll demonstrate by getting the latest three images from Flickr
using their interestingness.getList
method. Update the code_controller.rb file from the
previous examples to contain this new flickrtest method. Here is the code for our
controller:
class CodeController < ApplicationController
def flickrtest
flickruri = "http://www.flickr.com/services/xmlrpc/"
server = XMLRPC::Client.new2(flickruri)
flickrkey = "YOUR FLICKR KEY"
details = {:api_key => flickrkey, :per_page => "3"}
result = server.call("flickr.interestingness.getList", details)
@doc = REXML::Document.new result
end
endAnd here's the view that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access