DZone
Mobile Zone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
  • Refcardz
  • Trend Reports
  • Webinars
  • Zones
  • |
    • Agile
    • AI
    • Big Data
    • Cloud
    • Database
    • DevOps
    • Integration
    • IoT
    • Java
    • Microservices
    • Open Source
    • Performance
    • Security
    • Web Dev
DZone > Mobile Zone > Flickr API for Windows Phone 7 – Part 5 – Activity – User Comments

Flickr API for Windows Phone 7 – Part 5 – Activity – User Comments

Denzel D. user avatar by
Denzel D.
·
Oct. 01, 10 · Mobile Zone · Interview
Like (0)
Save
Tweet
8.12K Views

Join the DZone community and get the full member experience.

Join For Free

When a user signs up for Flickr, chances are he/she will not only post his/her own pictures, but also view other published photo materials. And sometimes (depends on the user) comments will be posted on other people's photos. In this article, I am showing how to obtain the list of comments a user posted on other people's content.

This is made possible with the help of flickr.activity.userComments. Knowing that you follow the "Flickr API for Windows Phone 7" series, you should already have an Activity class inside your project (in the Core folder). You only need to add one method to it:

public void GetUserComments(string apiKey, string signature, string authToken, HelperDelegate helperDelegate, string page = "", string resultsPerPage = "")
{
    helperDelegateInstance = helperDelegate;

    WebClient client = new WebClient();
    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
    string URL = string.Format("http://www.flickr.com/services/rest/?method=flickr.activity.userComments&api_key={0}&api_sig={1}&auth_token={2}&format=json",
            apiKey, signature, authToken);

    if (page != "")
        URL += "&page=" + page;
    if (resultsPerPage != "")
        URL += "&per_page=" + resultsPerPage;

    client.DownloadStringAsync(new Uri(URL));
}

GetUserComments is very similar to GetUserPhotos - the only major difference is the fact that it doesn't have the timeframe parameter - the API endpoint won't accept it and it is not documented.

Obviously, the URL is different - but once again, the only change here is the method name and the absence of references to timeframe. One thing worth noticing here is the fact that I am using the same event handler for data download completion - client_DownloadStringCompleted. As I mentioned in my prvious article, there is only one common property that stores the result for both methods, called LastActivityResult. This property can be set by both methods when the JSON data is received, therefore I am taking this opportunity to make the event handler common - shared between two methods and triggered depending on the instance call.

Let's test this method now. Somewhere in the main page (it's good if you have the test page I mentioned in my previous article) use this snippet:

param = new Dictionary<string, string>();
param.Add("api_key", "APIKEY");
param.Add("method","flickr.activity.userComments");
param.Add("auth_token", "TOKEN");
param.Add("format", "json");

Core.Authentication.GetSignature(param, "SECRET", () =>
{
    txtLog.Text += "\nGetting list of comments...";
    Core.Activity activity = new Core.Activity();

    activity.GetUserComments(apiKey, Core.Authentication.Signature, "TOKEN", () =>
    {
        txtLog.Text += "\n" + activity.LastActivityResult;
    });
});

One thing to mention here - the use of the API key, the token and the secret will be so frequent, that you might want to store them as settings in the isolated storage later on. Since right now I am only showing how to build the core, the experimental code is fine, but eventually for easier reuse it would make sense to make these values persistent.

Speaking of the token, once you get the full token, you can reuse it multiple times instead of generating a new one everytime the application starts - your app is already authorized for a specific user and all you have to do is reference the existing full token whenever requested.

Let's see what we get when the code above is executed!

Congratulations! Now you can keep track of your activity on other people's content! This becomes quite handy when you don't remember where was your last comment or what you said about a specific picture. And although this method is quite useful, it is recommended that you do not call it more than once an hour - for Flickr performance reasons.

API code style Windows Phone

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Creating a REST Web Service With Java and Spring (Part 1)
  • Comparing Distributed Databases
  • Instancio: Test Data Generator for Java (Part 2)
  • An Overview of Key Components of a Data Pipeline

Comments

Mobile Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • MVB Program
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends:

DZone.com is powered by 

AnswerHub logo