There's a new assembly available in the mono svn repository, module google-sharp. The classes it contains lets you authenticate to a Google service and there also support for managing your Picasa web galleries. As a plus, it also contains monodoc documentation.
Authenticating
The authentication process logs securely into the service as a web browser would do and retrieves the cookies needed. Once we those cookies, we can access the service over HTTP.
class Test {
public GoogleConnection Connect (string user, string passwd)
{
GoogleConnection conn = new GoogleConnection (GoogleService.Picasa);
ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
conn.Authenticate (user, passwd);
return conn;
}
}
In the example, we create a GoogleConnection to be used with Picasa web and do the authentication for the given user and password. Setting the CertificatePolicy to that value will make it accept any server certificate when using an HTTPS connection. To know more about why that is needed (and other ways of achieving the same) see the Mono security FAQ.
Managing a Picasa Web gallery
Once you're authenticated, you can create an album:
string unique_id = picasa.CreateAlbum ("My first album");
PicasaAlbumCollection coll = picasa.GetAlbums ();
PicasaAlbum album = coll [unique_id];
Download all the pictures in it:
foreach (PicasaPicture picture in pics.AllValues) {
using (Stream stream = File.OpenWrite (picture.Title)) {
picture.DownloadToStream (stream);
}
}
Upload a new picture to an album:
Of course, there's a caveat: currently the authentication process fails when running under MS.NET (too many redirections), so that means that:
- We have a bug in Mono that I'm not going to fix by now.
- I have to figure out how to make that work on MS
Hopefully, this will open the door for a Picasa Web plugin for f-spot, as Picasa for linux lacks support for Picasa Web. A command-line tool for uploading pictures is on the way.
Enjoy!
blog comments powered by Disqus