Hey Flickr, Where Did My Statistics Go? OAuth, the Flickr API and You. (Part II)   1 comment

This is Part II of my series on the Flickr API and View Statistics.  You can find Part 1 here.

Assume a C# static class containing the critical information you need to identify yourself to Flickr:

public static class User{

public static string FullName {get;set;}

public static string Username {get;set;}

public static string UserId {get;set;}

public static string APIKey {get;set;}

public static string SharedSecret {get;set;}

public static string Token {get;set;}

public static string TokenSecret {get;set;}

}

Where APIKey and SharedSecret identify you (as the developer) to Flickr and Token and TokenSecret identify your relationship with the user which encodes what rights the user has granted to you.

14388202106_613a1b18f2_o

 

FlickrNet defines a C# class OAuthAccessToken as:

 public class OAuthAccessToken : IFlickrParsable
{

        public string UserId {get;set;}

        public string USername {get;set;}
public string Token { get; set; }
public string TokenSecret { get; set; }
}
}

14601596573_4bbaa2477e_o

Given the above, to get things rolling we need to populate the FlickrNet OAuthAccessToken fields from our User class, and then instantiate FlickrNet’s FlickrManager:

OAuthAccessToken o = new OAuthAccessToken();

o.Token=User.Token;

o.TokenSecret=User.TokenSecret;

o.UserId=User.UserId;

o.Username=User.Username;

FlickrNet.Flickr _F = FlickrManager.GetAuthInstance(User.APIKey, User.SharedSecret);

Now we can loop through our photos getting the number of views for each photo on the datetime of the call.  We do these with paged calls to FlickrNet’s PeopleGetPhotos:

public PhotoCollection PeopleGetPhotos(PhotoSearchExtras extras, int page, int perPage);

14528978934_61edc51d2c_o

Here is a simple loop to do so (without error checking):

int page=0;

while (true){

PhotoCollection photo = _F.PeopleGetPhotos(PhotoSearchExtras.Views, page++, 500);

     if (photo.Count == 0){ break; }

//Loop through each photo on the page:

foreach (FlickrNet.Photo p in photo)
{
//Save The Results

    SaveByID(User.UserID,p.PhotoID, p.Title, p.ThumbnailURL, p.Views); 

}

}

OK so far?  Note that in FlickrNet the Views field is defined as int? (which means that Views may contain a null) For our purposes here we will regularly convert those nulls to zeros.  The Views is not a delta but the total number of views (clicks since the photo was first posted up to the time in which the call is made).  Most of our next post will discuss one approach to collect and store views per day (or some other sample period).

ThumbnailURL can be used to retrieve the thumbnail of the image.  Note here that starting last month Flickr increased the default size of the thumbnails on new photos.  We will come back to this issue in a later post which deals with displays.  Speaking of display there is a field called LargeURL associated with each Flickr Photo object but we have had trouble working with.  Instead I will display full size images within Flickr using the formula:

https://www.flickr.com/photos/{full user name no spaces}/{photoID/in/photostream/

Example:

https://www.flickr.com/photos/dennisredfield/14588760519/

display the Flickr page for this photo.

14588760519_b7ce0afceb_o

 

Series continues here.

 

Posted 2014/07/29 by Cloud2013 in Flickr, FlickrNet, Photography

Tagged with , ,

One response to “Hey Flickr, Where Did My Statistics Go? OAuth, the Flickr API and You. (Part II)

Subscribe to comments with RSS.

  1. Pingback: Hey Flickr, Where Did My Statistics Go? OAuth, the Flickr API and You. | Cloud2013 Or Bust

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 122 other followers

%d bloggers like this: