Rather than writing thesis, I prefer coding for fun. After playing with the blogger API last time, today I write a brute-force code-snippet to grab all the photos from my picasa web album and store them onto the disk :)
In order to run the following code, you must have C# 3.5 compiler with .NET Google API SDK on your hand. Enjoy.// All C# code by Joshua
using System;
using System.Drawing;
using Google.GData.Client;
using Google.GData.Photos;
// The owner of the album
var userName = @"garfilone@gmail.com";
// Local store location
var folder = @"D:\picasa_test\";
// Initializes a new PicasaService instance
var service = new PicasaService("picasa-pic-grabber");
// Optional set the user credentials
//service.setUserCredentials("xxxx@gmail.com", "xxxxx");
// Sets the callback method of asynchronized operation
service.AsyncOperationCompleted += (s, e) =>
{
var name = (e.UserState as PicasaEntry).Title.Text;
Image.FromStream(e.ResponseStream).Save(folder + name);
Console.WriteLine("Writing " + name + " to " + folder + name);
};
// Queries the album list
var aQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri(userName));
var aFeed = service.Query(aQuery);
// For each album
foreach (var aEntry in aFeed.Entries)
{
Console.WriteLine(aEntry.Title.Text);
var pQuery = new PhotoQuery(aEntry.FeedUri);
var pFeed = service.Query(pQuery);
// For each photo
foreach (PicasaEntry pEntry in pFeed.Entries)
{
Console.WriteLine(pEntry.Title.Text);
service.QueryStreamAync(new Uri(pEntry.Media.Content.Url),
DateTime.MinValue, pEntry);
}
}
Console.ReadLine();
没有评论:
发表评论