Google has launched Picasa Web Albums Data API in march 2007 . Last week , I developed some code using this new API which is part GData API family. In case you are still wondering what GData APIs consists of then check out the official homepage.
Here are some of the things you can do with the Picasa Web Albums Data API:
- Include your public photos in your own web page, and allow users to comment on them (and have the comments stored in Picasa Web Albums).
- Write a plugin to manage your albums and photos from a desktop or mobile phone client.
- Create a custom screensaver to display your Picasa Web Albums photos on your computer.
Google is providing client libraries to help you write GData client applications in a variety of languages like java, python, c#, php, javascript.
Download the GData .NET Client Library
Now, create a new Console Application project for c#. Add a reference to GData.Client, Gdata.Extenstion and GData.Photos Dlls from the output directory of the first project.
Now the stage is ready.
Here is the code for a function which takes User name and name of the album as arguments and download all the pictures from this album.
private static void DownAlbum(string UserN, string AlbumN)
{
string fileName;
Uri uriPath;
WebClient HttpClient = new WebClient();
// Three important elements of PicasaWeb API are
// PhotoQuery, PicasaService and PicasaFeed
PhotoQuery query = new PhotoQuery();
query.Uri = new Uri(PhotoQuery.CreatePicasaUri(UserN, AlbumN));
PicasaService service = new PicasaService("Sams PicasaWeb Explorer");
PicasaFeed feed = (PicasaFeed)service.Query(query);
Directory.SetCurrentDirectory("c:\\");
foreach (AtomEntry aentry in feed.Entries)
{
uriPath = new Uri(aentry.Content.Src.ToString());
fileName = uriPic.LocalPath.Substring(uriPath.LocalPath.LastIndexOf('/')+1);
try {
Console.WriteLine("Downloading: " + fileName);
HttpClient.DownloadFile(aentry.Content.Src.ToString(), fileName);
Console.WriteLine("Download Complete");
}
catch (WebException we)
{ Console.WriteLine(we.Message); }
}
Code is easy to understand. I am using HttpClient.DownloadFile() to download file from picasaweb server. To improve readability I have not included error handling code here.