DZone
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
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
  1. DZone
  2. Data Engineering
  3. Databases
  4. Flickr API for Windows Phone 7 – Part 7 – Collections

Flickr API for Windows Phone 7 – Part 7 – Collections

Denzel D. user avatar by
Denzel D.
·
Oct. 05, 10 · Interview
Like (0)
Save
Tweet
Share
8.44K Views

Join the DZone community and get the full member experience.

Join For Free

Flickr has a feature called collections that allows you to group photo sets and other collections in larger groups. One important thing to mention here is that collections are only available for pro (paid) accounts on Flickr, so if you don’t have one, then you won’t be able to directly test this code. However, I’d still recommend having it in your application, since the end user might be using a pro account.

So to start, there are two methods that allow working with collections:
•    getInfo – gets the list of photos/collections/sets inside a single collection
•    getTree – returns a list of collections that are created by the end user

I went ahead and created a Collections class using the same class template I’ve used in my previous example, so the skeleton looks like this:

using System;
using System.Net;
using System.Windows;
 
namespace FlickrWP7.Core
{
    public class Collections
    {
        private HelperDelegate helperDelegateInstance;
 
        public string LastCollectionResult { get; set; }
    }
}

The getInfo method implementation follows the standard pattern – it requires authentication, so there will be the authentication token and the signature. Together with the tied event handler (triggered when JSON data is downloaded) it looks like this:

public void GetCollectionInfo(string apiKey, string signature, string collectionID, HelperDelegate helperDelegate)
{
    helperDelegateInstance = helperDelegate;

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

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

void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    LastCollectionResult = e.Result;
    helperDelegateInstance();
}

The collectionID parameter can be found through the web browser address bar when you navigate to a specific collection. It is a required parameter for this method and you cannot skip it. Now all I have to add is the getTree implementation.

This method does not require authentication, so there is no need to generate the signature and you don’t need to pass the authentication token. The API key is, however, required.

public void GetCollectionTree(string apiKey, HelperDelegate helperDelegate, string collectionID = "", string userID="")
{
    helperDelegateInstance = helperDelegate;

    WebClient client = new WebClient();
    client.DownloadStringCompleted += new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
    string URL = string.Format("http://www.flickr.com/services/rest/?method=flickr.collections.getTree&api_key={0}&format=json",
            apiKey);

    if (collectionID != "")
        URL += "&collection_id=" + collectionID;
    if (userID != "")
        URL += "&user_id=" + userID;

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

The collectionID parameter here is optional. If you specify it, a list of collections will be returned that belong to the specified collection. The userID is also optional and will return the collection set for a specific user (defined by a unique ID).

The Collections.cs file is attached here, so you can easily insert it into the existing project.

API Windows Phone

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • Reliability Is Slowing You Down
  • Cloud Performance Engineering
  • gRPC on the Client Side
  • Container Security: Don't Let Your Guard Down

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • 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: