Delphi REST client to retrieve flickr statistics

It's been a while since I last posted an article here, and today I'm coming with an exciting application I have been working on lately called "flickr photo stats". I'm a keen photographer and I like posting all my pictures in Flickr as it's a great platform for sharing and publishing your work. You can find my profile here:
What's most important is that Flickr provides an API which allows you to request information about your pictures. The Flickr API is available for non-commercial use by outside developers and we can request an API key for our particular use. To use the Flickr API, you need to have an application key that can be requested here: The App garden. As mentioned before this application key is for personal use and I had to request mine and explain the intentions for its use as I only wanted to get some values from my photos and keep track of them.


What I'm trying to achieve...

If I open one of the pictures, I can see that every picture contains 3 main values regarding statistics:
  - Views: Number of views that the picture receives.
  - Favourites: Number of likes that the picture receives.
  - Comments: Number of comments that the picture receives.
In previous versions of Flickr, they offered a professional profile in where users could see the global stats for the entire portfolio. Now with the new version, they only show the values for individual pictures. Many other platforms like ViewBug or 500px show the total number of views and other interesting information that could be useful when building your portfolio and study the data to see what people are more interested in seeing in your profile. I spent a while going through some forums in Flickr, trying to see if someone had created an additional service or application to display the information of the profile, but after weeks of research, nothing original came up.

Then I started doing my own research as to see how difficult or easy it would be to request the information from the API and when going through the definition of it I saw that they provide a REST request/response. A smile was drawn to my face :) when I immediately thought that I could build a REST client with Delphi and get the information I needed easily.

I'm on the phase of testing Delphi XE6 so I developed the application with it. :)

My solution

The requirement is to get as much information regarding the number of views, comments and likes from your portfolio. As the profile could have many pictures, this application only focuses in the photos you want to track e.g. the number of views overtime of one of your photos or counting the total views, likes and comments for the photos you add into the app list.

My current solution is really simple and effective after the results of my testing. Here you can see a screenshot of the application:
On the left, a list of photos containing the ID, title, number of views, likes, comments and the last time the application update the counters.
On the right a view of one of the pictures with the number of views (depending on the selection) over time. The application allows a batch update where it will request an update all the counters. Every day the system creates a new entry under a particular photo, so we can keep track of the overtime. Current example is just showing the data from the last 3 days.
The application stores all the details in an internal repository in XML format (see figure below) and it can be loaded/saved any time. The app is still under development so there could be bugs but it works fine.
The REST client uses a IdHTTP component with a IdSSLIOHandlerSocketOpenSSL handler as Flickr uses https
The main API methods used by the app are:
  • flickr.photos.getFavorites (Returns the list of people who have favorited a given photo)
    • Arguments:
      • api_key (Required) Your API application key.
      • photo_id (Required). The ID of the photo to fetch the favoriters list for
  • flickr.photos.getInfo (Get information about a photo. The calling user must have permission to view the photo)
    • Arguments:
      • api_key (Required) Your API application key.
      • photo_id (Required). The ID of the photo to fetch the favoriters list for
Example response:

Once we get the values from the REST response, we can use a XMLDocument component to read the values we need:


How to start 

Once you have your application key sorted out, you can check that your API key works by running the test echo that Flickr service API provides:

An example response is as follows:


From here we will use the api_key value and place it into the apy key textbox in the app:

To know what's your photo_id, you just need to open your picture on Flickr and you will get the ID on the URL:

Once we have the photo_id we can add it into the list and the application will add a new entry. If we click on the checkbox associated to the entry, the graph on the right will be displayed with the values (current and stored). The graph is dynamically build so you can add/remove as many as you want. A selection of views/likes/comments is possible under the graph so every time a selection is made, the graph is generated displaying one of those selected values.
At the end of the main list there is a label that tallies up all the values from the list which gives you a great indication about how your pictures are doing.

Source code and binaries can be found here:
Enjoy the reading and do not hesitate to add your comments and thoughts about it. There are still many things to fix and enhance but at least I can get some meaningful values and track items easily without having to explore each single picture on Flickr.
A better example is shown in the figure below after adding 275 photos into the app:
I can easily see that those pictures have reached more than 200k views in total which gives me a good indication of the amount of visits the profile gets. As I run the app every day (to keep track of everything), I can see that the number of views are going up.

Update 20/07/2014.
A second version of the up is ready and it just enhances the way information is displayed:


New version here:

Jordi

Comments

Popular Posts