Tuesday, October 23, 2012

Google Picasa Web API
How to pull Album data size from Picasa web Albums?

On this site I have published many post on how to use Google Picasa web API with .NET. This article is another extension to the set of articles on Picasa Web API with .NET.

All of us love to share or store our favourite pictures on various Social Media sites. Google Picasa Web is one of the popular media to store photos online. With each photo that we stored in Picasa web album, we consumed some space. Over the time as we add more and more photos to our web album, the album size is grown.

With .NET if your requirement is to pull each of the web album data size, you can use Google Data API and read this information. In this article we will learn how we can pull the data size of each Picasa web album using .NET.

The prerequiste for this is you must have Google Data API installed on your sytem and you can use any of your visual studio IDE 2005/2008/20010 or 2012. You also need an active Internet connection as you will be pulling online information.

For demonstration purpose I have created following form in Visual Studio 2008.

I have two text boxes to take Google credentials as input. Once the use enter their Google credentials, they need to click on Login. The code logic written on Login button create an instance of Picasa web service and pass on the credentials to Picasa web service. If the Google credentials are correct a message appears on the form to ask user to clikc on Album Size.

Once the user click on Album Size button the code logic written on this button pulls all the web albums and their respective data size . The album name and their size will be shown in the list box. Google Picasa feed provides data size in bytes. So if you need to convert the data size from bytes to Megabytes or Gigabytes you can do it.

The .NET code logic on this form is following:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Google.GData.Client;

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

namespace TestDOTNET
{
    public partial class Form1 : Form
    {
        String myAlbumID;
        PicasaService myPicasa;
        AlbumQuery myAlbumQuery;
        PicasaFeed myPicasaFeed;

        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {


            myPicasa = new PicasaService("Vikash-Test-Picasa");
            myPicasa.setUserCredentials(textBox1.Text, textBox2.Text);
            label3.Text = "Click on Album Size to get albums storage size.";
        }

        private void button2_Click(object sender, EventArgs e)
        {
            listView1.Columns.Add("Album Title");
            listView1.Columns.Add("Album Size");

            listView1.FullRowSelect = true;


            myAlbumQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri(textBox1.Text));
            myAlbumQuery.KindParameter = "album";
            

            myPicasaFeed = myPicasa.Query(myAlbumQuery);
            foreach (PicasaEntry p in myPicasaFeed.Entries)
            {

                AlbumAccessor myAlbum = new AlbumAccessor(p);
                listView1.Items.Add((new ListViewItem(new string[] { myAlbum.AlbumTitle.ToString(), myAlbum.BytesUsed.ToString() })));
            }


        }
    }
}

No comments:

Post a Comment

Please feel free to write your Comment here

Popular Posts

Real Time Web Analytics