A modern, fully-featured .NET client library for the Flickr API with dependency injection, IHttpClientFactory integration, and optional HybridCache support.
- πΌοΈ Photo Management - Upload, download, search, and organize photos
- π Albums & Collections - Create and manage photo albums and collections
- π¨ Galleries - Browse and interact with Flickr galleries
- π₯ User Management - Access user profiles, contacts, and favorites
- π Advanced Search - Powerful search capabilities with filtering
- π·οΈ Tags & Metadata - Full support for tags, EXIF data, and metadata
- π OAuth Authentication - Secure authentication with OAuth 1.0a
- β‘ Async/Await - Modern async API throughout
- π¦ Strongly Typed - Type-safe API with comprehensive models
- π Dependency Injection - First-class DI support with
IHttpClientFactory - ποΈ Optional Caching - Opt-in response caching via
HybridCache
Install via NuGet Package Manager:
dotnet add package Flickr.NetOr via Package Manager Console:
Install-Package Flickr.Net// Program.cs
services.AddFlickr(o =>
{
o.ApiKey = "your-api-key";
o.SharedSecret = "your-shared-secret";
});
// Optional: enable response caching
services.AddFlickrCaching();// Inject IFlickrClient anywhere
public class PhotoService(IFlickrClient flickr)
{
public async Task<Photo> GetPhotoAsync(string id, CancellationToken ct)
{
return await flickr.Photos.GetInfoAsync(id, ct);
}
}using var flickr = new FlickrClient("your-api-key", "your-shared-secret");// 1. Get a request token
var requestToken = await flickr.OAuth.GetRequestTokenAsync("https://your-callback-url");
// 2. Send user to Flickr authorization page
var authUrl = $"https://www.flickr.com/services/oauth/authorize?oauth_token={requestToken.Token}";
// 3. After user authorizes, exchange for access token
var accessToken = await flickr.OAuth.GetAccessTokenAsync(requestToken, "verifier-code");
// 4. Store and set the tokens for future requests
flickr.FlickrSettings.OAuthAccessToken = accessToken.Token;
flickr.FlickrSettings.OAuthAccessTokenSecret = accessToken.TokenSecret;var options = new PhotoSearchOptions
{
Text = "sunset",
Tags = "nature,landscape",
PerPage = 20,
Extras = PhotoSearchExtras.DateTaken | PhotoSearchExtras.Description
};
var photos = await flickr.Photos.SearchAsync(options);
foreach (var photo in photos)
{
Console.WriteLine($"{photo.Title} by {photo.OwnerName}");
}await using var stream = File.OpenRead("photo.jpg");
var photoId = await flickr.Upload.UploadPictureAsync(
stream,
"photo.jpg",
title: "Sunset at the beach",
tags: "sunset beach vacation",
isPublic: true);// Create an album
var album = await flickr.Photosets.CreateAsync("Vacation 2024", "primary-photo-id");
// Add photos to album
await flickr.Photosets.AddPhotoAsync(album.PhotosetId, "photo-id");
// Get album photos
var albumPhotos = await flickr.Photosets.GetPhotosAsync(album.PhotosetId);// Add to favorites
await flickr.Favorites.AddAsync("photo-id");
// Get user's favorites
var favorites = await flickr.Favorites.GetListAsync();
// Remove from favorites
await flickr.Favorites.RemoveAsync("photo-id");// Add a comment
var commentId = await flickr.PhotosComments.AddCommentAsync("photo-id", "Great photo!");
// Get all comments
var comments = await flickr.PhotosComments.GetListAsync("photo-id");
// Add a note to a photo
await flickr.PhotosNotes.AddAsync("photo-id", 100, 100, 50, 50, "This is a note");IFlickrClient organizes the Flickr API into sub-clients:
flickr.Photos // Search, get info, manage photos
flickr.Photosets // Albums / photosets
flickr.People // User profiles, find by email/username
flickr.Favorites // Add, remove, list favorites
flickr.Groups // Browse and manage groups
flickr.GroupsPools // Group photo pools
flickr.Tags // Tag management and search
flickr.Galleries // Gallery operations
flickr.Contacts // Contact management
flickr.Upload // Upload and replace photos
flickr.OAuth // OAuth 1.0a authentication flow
flickr.Stats // View counts and referrers
flickr.Places // Place and location search
flickr.PhotosComments // Photo comments
flickr.PhotosGeo // Geolocation data
flickr.PhotosNotes // Photo annotations
flickr.Interestingness // Interesting photos
flickr.MachineTags // Machine tag operations
// ... and moreResponse caching is opt-in via HybridCache:
// Basic in-memory caching
services.AddFlickrCaching();
// With custom expiration
services.AddFlickrCaching(o =>
{
o.DefaultEntryOptions = new() { Expiration = TimeSpan.FromMinutes(10) };
});
// With distributed L2 cache (e.g. Redis)
services.AddFlickrCaching();
services.AddStackExchangeRedisCache(o => o.Configuration = "localhost:6379");Without AddFlickrCaching(), every API call goes directly to Flickr β no caching overhead.
Configure extras that are automatically included in every search:
services.AddFlickr(o =>
{
o.ApiKey = "...";
o.SharedSecret = "...";
o.DefaultSearchExtras = PhotoSearchExtras.Description | PhotoSearchExtras.DateTaken;
});Upgrading from an earlier version? See the Migration Guide for breaking changes and upgrade steps.
Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- .NET 10.0 or higher
- Flickr API key and secret (Get yours here)
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Original FlickrNet library by Sam Judson