Thursday, May 17, 2012

How to pull photo list from Picasa web Album with Google Data API?

This post is next in series of our exploration of Google Data API library. We have learnt how to use Google Data API to externally access the Picasa Web Album.

In this post we will learn how we can pull photo list from Picasa Web Album. We will pull the image name, image summary, image published date and last updated date of each of the images stored in a particular Picasa web album.

To start with I have uploaded following five test images in our newly created Picasa web Album “Google is the Best”. We will pull the image list from this web album.

To pull images from Picasa Web Album; the very first thing you need is AlbumID. You can navigate to the Picasa web account and copy the link address of RSS link. The link address has albumID of the web album in following format:

https://picasaweb.google.com/data/feed/base/user/[Numeric userID]/albumid/[Numeric AlbumID]?alt=rss&kind=photo&hl=en_US

You can copy the album id as this you need to use in your code snippet.

I created following .NET interface in C#. The form has a list view and a button. The list view will show the image name, image summary etc details after clicking on “Get Photo List” button.

The.NET code snippet to pull the image list is following:

private void button1_Click(object sender, EventArgs e)
{
//Add four columns in the listview
 listView1.Columns.Add("Photo Title");
 listView1.Columns.Add("Photo Summary");
 listView1.Columns.Add("Published Date");
 listView1.Columns.Add("Last Updated");

//Create Picasa Service
 PicasaService myPicasa = new PicasaService("Vikash-Test-Picasa");

//Pass on user credentials (userID and password) 
 myPicasa.setUserCredentials("abc@gmail.com", "abcpassword");

//create photoqueyr by passing userid and albumid
 PhotoQuery myPhotoQuery = new PhotoQuery(PicasaQuery.CreatePicasaUri("abc", "5737335314773942337"));

 PicasaFeed myPicasaFeed = myPicasa.Query(myPhotoQuery);
 foreach (PicasaEntry p in myPicasaFeed.Entries) 
 {
  listView1.Items.Add(new ListViewItem(new string[] { p.Title.Text, p.Summary.Text, p.Published.ToShortDateString(), p.Updated.Date.ToShortDateString() }));
 }
 }

We have created an instance of a photoquery and passed the userid and AlbumID as we need to tell which album photos we want to pull. The photoquery is passed to PicasaFeed which in turn connect with the Google Picasa Feed and pull the desired information.

After running the form I clicked on “Get Photo List” button. The code runs successfully and pulled the photo list, photo summary, published date and last updated date for each of the image stored in Picasa web album.

So our objective to pull photo list from Picasa Web albums have been achived.

Thanks for reading till this point.

If you want to explore more with the Source code of this post; please visit Download Zone.

Popular Posts

Real Time Web Analytics