Im building my first app in rails and I would like to call Flickr's API
I know I can use flickr-fu, rflickr or other gem but I want to do it myself from scratch to learn
Say, for example, I want to call flickr.photos.comments.getList
that returns the comments for a photo. The arguments are api_key and photo_id. I have both.
I will get the response as an xml
<comments photo_id="109722179">
<comment id="6065-109722179-72057594077818641" author="35468159852@N01" authorname="Rev Dan Catt" datecreate="1141841470" permalink="http://www.flickr.com/photos/straup/109722179/#comment72057594077818641">
Umm, I'm not sure, can I get back to you on that one?</comment>
</comments>`
I want to store the data received by calling that method into a variable comments
that I can access the data using, for example,
comments.all.first.author_name = "Rev Dan Catt"
or
comments.all.first.content = "Umm, I'm not sure, can I get back to..."
How can I do this? Please be patient (sorry for the noob question)
Obtaining an API key You must have an Yahoo! account to log in to the flickr.com or if you don't have one, you have to sign up to Flickr. Once you are within Flickr, point your browser to https://www.flickr.com/services/api/. Go to 'Create an APP' for creating an API key. Click on the link "Request an API Key".
Getting Started To begin using the Flickr API: Request an API key, to sign your API requests. Read the Community Guidelines and the API Terms of Use. Build, build, build.
Go to the Flickr API Services page. If you have not yet logged into your Flickr account, you will be asked to do so. Once you have logged in, the Flickr Services page is displayed with some general information about API keys.
include 'rubygems'
include 'httparty'
class Flickr
include HTTParty
base_uri 'api.flickr.com'
def self.getPhotos(uid)
return get('/services/rest/', :query => {
:method => 'flickr.people.getPublicPhotos',
:api_key => 'api key goes here',
:user_id => uid})
end
end
and then call
Flickr.getPhotos('12345678')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With