Wednesday, June 24, 2009

Google Picasa Photos Sample

Now it's time for Google Picasa. You may be wondering why in the hell am I working on Data API's. Well my idea is to integrate these modules with my Clutter Application launcher. First thing I have to do is to get these module to work in Linux using mono and then comup with an IPC to share info between Mono App and Clutter Application Launcher so that I can display info fetched from Google Servers. This is going to take some time. I will post a video here once I am done with it. For now have fun with the code snippet below.





using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net.Sockets;

using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Photos;
using Google.GData.Extensions.Location;
using System.IO;

namespace GooglePicasaPhotos
{
class Program
{
static void Main(string[] args)
{
GetPicasaPhotos();
}

static void GetPicasaPhotos()
{
PicasaService Service = new PicasaService("GooglePicasaPhotos");
Service.setUserCredentials("mail-id@gmail.com", "password");

AlbumQuery Query = new AlbumQuery(PicasaQuery.CreatePicasaUri("mail-id@gmail.com"));
PicasaFeed Feed = Service.Query(Query);

foreach (PicasaEntry Entry in Feed.Entries)
{
AlbumAccessor AA = new AlbumAccessor(Entry);
Console.WriteLine("Album Title : " + AA.AlbumTitle);
Console.WriteLine("No of Photos : " + AA.NumPhotos.ToString());

Stream stream = Service.Query(new Uri(Entry.Media.Thumbnails[0].Url.ToString()));
Bitmap bitmap = new Bitmap(stream);
System.IO.Directory.CreateDirectory(AA.AlbumTitle);
bitmap.Save(AA.AlbumTitle + "\\" + "Album Thumbnail.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);

PhotoQuery PhotoQuery = new PhotoQuery(Entry.FeedUri.ToString());
PicasaFeed PhotoFeed = Service.Query(PhotoQuery);

foreach (PicasaEntry PhotoEntry in PhotoFeed.Entries)
{
PhotoAccessor PAA = new PhotoAccessor(PhotoEntry);
Console.WriteLine("Photo Title : " + PAA.PhotoTitle);

for (int i = 0; i < PhotoEntry.Media.Thumbnails.Count; i++)
{
Console.WriteLine("Width = " + PhotoEntry.Media.Thumbnails[i].Width + " Height = " + PhotoEntry.Media.Thumbnails[i].Height);
}
Stream pstream = Service.Query(new Uri(PhotoEntry.Media.Thumbnails[0].Url.ToString()));
Bitmap pbitmap = new Bitmap(pstream);
pbitmap.Save(AA.AlbumTitle + "\\" + PAA.PhotoTitle, System.Drawing.Imaging.ImageFormat.Jpeg);

}
}

Console.WriteLine("\n\n");
}
}
}



No comments: