| | |
|
|
|
Flickr services
This Project Zero extension provides an easy way to read and write Flickr's photo data from Java or Groovy without creating cumbersome request URLs. All requests made through this API are serviced by Flickr's REST API. You need a Flickr account and an API key to use the extension.
Adding Flickr to your project
You can access the Project Zero API for Flickr by adding the zero:zero.flickr module to your project. To do this, add the following line to your config/ivy.xml file:
<dependency org="zero" name="zero.flickr" rev="1.0+"/>
Add your Flickr API key to the zero.config file of your application, as shown in the following example:
/config/flickr/key = 1234567890
To access the Project Zero API for Flickr from your Java code, you can use the zero.flickr.FlickrClient class directly; from Groovy code, you can use the flickr variable, which is automatically added to the scope of your Groovy scripts.
Reading user and photo data
To query user and photo data using the extension, provide a method name and a set of parameters to the query() method, as shown in the following example:
def method = "flickr.photosets.getPhotos";
def params = [
photoset_id: 1234567890,
page: 1,
per_page: 20
];
def response = flickr.query(method, params); // response is a JSON object
If you query a method that returns one or more photo data structures, you can easily obtain the various URLs to the actual images:
for (i in 0 .. response.photoset.photo.length - 1)
{
def thumbnailURL = thumbnail(response.photoset.photo[i]);
def smallURL = small(response.photoset.photo[i]);
def mediumURL = medium(response.photoset.photo[i]);
def originalURL = original(response.photoset.photo[i]);
// use URLs to set <img/> tags...
}
Modifying user and photo data
You can modify or delete Flickr data using the post() and delete() methods. These are very similar to the query() method call with the additional requirement that the user be authenticated. Flickr's documentation describes setting up authentication for applications that integrate with its service; the Zero API can help you implement this scheme with the createSignature() method.
You can use createSignature() to create the API call signature required of write-only methods. The parameters you use with this method are your Flickr API (that you got when you registered for your API key) and the parameters you intend to pass to the method. The implementation uses these values to generate a Flickr-approved signature value.
|
r3 - 07 Feb 2008 - 21:26:08 - paynel
|
|
|
| | |
|