I am a bit stumped here as the Flickr documentation makes mention of Collections and Galleries but nothing I've found related to Albums.
I am building a website in asp.net and want to load photos from a Flickr Album I have and after some time checking into the Collections and Galleries API with no luck I am hoping someone knows how to retrieve photos from a Flickr Album.
Here is what I have currently and it works well for photos from my photostream, but I've yet to figure out how to load Albums.
using System;
using System.Configuration;
using System.Web;
using FlickrNet;
namespace MyWebSite.Core.Gateways
{
public class FlickrGateway : IFlickrGateway
{
private readonly string _flickrApiKey = ConfigurationManager.AppSettings["Flickr.ApiKey"];
private readonly string _flickrApiSecret = ConfigurationManager.AppSettings["Flickr.ApiSecret"];
private readonly string _flickrApiUserId = ConfigurationManager.AppSettings["Flickr.ApiUserId"];
private readonly string _flickrPhotoSetId = ConfigurationManager.AppSettings["Flickr.PhotoSetId"];
private readonly Flickr _flickrApi;
public FlickrGateway()
{
_flickrApi = new Flickr(_flickrApiKey, _flickrApiSecret) { InstanceCacheDisabled = true };
if (OAuthToken == null) return;
_flickrApi.OAuthAccessToken = OAuthToken.Token;
_flickrApi.OAuthAccessTokenSecret = OAuthToken.TokenSecret;
}
public PhotoCollection GetPhotoStream()
{
return _flickrApi.PeopleGetPublicPhotos(_flickrApiUserId);
}
public PhotosetCollection GetPhotosetsList()
{
return _flickrApi.PhotosetsGetList(_flickrApiUserId);
}
public PhotosetPhotoCollection GetPhotoSet(string photoSetId)
{
return _flickrApi.PhotosetsGetPhotos(photoSetId);
}
public PhotosetPhotoCollection GetPhotoSet()
{
return _flickrApi.PhotosetsGetPhotos(_flickrPhotoSetId);
}
private static OAuthAccessToken OAuthToken
{
get
{
if (HttpContext.Current.Request.Cookies["OAuthToken"] == null)
{
return null;
}
var values = HttpContext.Current.Request.Cookies["OAuthToken"].Values;
return new OAuthAccessToken
{
FullName = values["FullName"],
Token = values["Token"],
TokenSecret = values["TokenSecret"],
UserId = values["UserId"],
Username = values["Username"]
};
}
set
{
var cookie = new HttpCookie("OAuthToken")
{
Expires = DateTime.UtcNow.AddHours(1),
};
cookie.Values["FullName"] = value.FullName;
cookie.Values["Token"] = value.Token;
cookie.Values["TokenSecret"] = value.TokenSecret;
cookie.Values["UserId"] = value.UserId;
cookie.Values["Username"] = value.Username;
HttpContext.Current.Response.AppendCookie(cookie);
}
}
}
}
To get album photos you will need to call flickr.photosets.getPhotos API method.
The corresponding method in .Net API is Flickr_Photosets.PhotosetsGetPhotos
.
As I can see you already have it: GetPhotoSet
.
So all you need is just to pass your albumId
as photoSetId
.