Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

Sascha Tayefeh http://www.tayefeh.de

« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS 

Using Google's API to Access Picasa Albums

Google provides its API in multiple languages. Here is an example that shows how to access a picasa album.

Before you start, you need to download Google's API for .NET. Then copy the files to you project (in the project explorer) in Visual Studio and in the references in the project explorer. Now you can make use of the namespaces:

using Google.GData.Client;
using Google.GData.Photos;

   1  
   2  namespace GetPicasaFeed
   3  {
   4      public partial class Form1 : Form
   5      {
   6          public Form1()
   7          {
   8              InitializeComponent();
   9              this.getAtomFeed();
  10              return;
  11          }
  12  
  13          private void getAtomFeed()
  14          {
  15  
  16              // Album query and picasa query are specialized atomfeed classes
  17              AlbumQuery aQuery = new AlbumQuery(PicasaQuery.CreatePicasaUri("saschatayefeh"));
  18              PicasaService pService = new PicasaService("PicasaDemo");
  19              AtomFeed kResultFeed = pService.Query(aQuery);
  20  
  21              foreach (AtomEntry entry in kResultFeed.Entries)
  22              {
  23                  this.textBox1.AppendText(entry.Title.Text + "\r\n");
  24                  foreach (AtomLink eLink in entry.Links)
  25                  {
  26                      this.textBox1.AppendText("  " + eLink.HRef.ToString() + "\r\n"); ;
  27                  }
  28              }
  29              return;
  30          }
  31  
  32   
  33      }
  34  }

Accessing a web service

1. In Visual Studio, add a web reference in the project explorer.

2. Create an class describing an object that represents the web service.

   1  
   2      public class CurrentWeather
   3      {
   4  
   5          #region attributes
   6  
   7          private String location;
   8          private String time;
   9          private String wind;
  10          private String visibility;
  11          private String temperature;
  12          private String dewPoint;
  13          private String relativeHumidity;
  14          private String pressure;
  15          private String status;
  16  
  17          #endregion
  18  
  19  
  20          #region properties
  21  
  22          public String Location { get { return this.location; } set { this.location = value; } }
  23          public String Time { get { return this.time; } set { this.time = value; } }
  24          public String Wind { get { return this.wind; } set { this.wind = value; } }
  25          public String Visibility { get { return this.visibility; } set { this.visibility = value; } }
  26          public String Temperature { get { return this.temperature; } set { this.temperature = value; } }
  27          public String DewPoint { get { return this.dewPoint; } set { this.dewPoint = value; } }
  28          public String RelativeHumidity { get { return this.relativeHumidity; } set { this.relativeHumidity = value; } }
  29          public String Pressure { get { return this.pressure; } set { this.pressure = value; } }
  30          public String Status { get { return this.status; } set { this.status = value; } }
  31  
  32          #endregion
  33  
  34      }



Use a method like this to call the service

   1  
   2          private void btRead_Click(object sender, EventArgs e)
   3          {
   4              net.webservice.www.MyWeather gw = new net.webservice.www.MyWeather ();
   5              this.lblShowStatus.Text = "Accessing Service";
   6              this.Refresh();
   7   
   8              Objects.CurrentWeather cwo = new Objects.CurrentWeather();
   9              System.Xml.Serialization.XmlSerializer xs =
  10                  new System.Xml.Serialization.XmlSerializer(typeof(Objects.CurrentWeather));
  11  
  12              // Deserialize
  13              try
  14              {
  15                  System.IO.TextReader tr = new System.IO.StringReader(gw.GetWeather(this.tbCity.Text, this.tbCountry.Text));
  16                  cwo = (Objects.CurrentWeather)xs.Deserialize(tr);
  17                  this.lblShowStatus.Text = cwo.Status;
  18                  this.lbShowHumidity.Text = cwo.RelativeHumidity;
  19                  this.lbShowPressure.Text = cwo.Pressure;
  20                  this.lbShowWind.Text = cwo.Wind;
  21                  this.lbShowTemperature.Text = cwo.Temperature;
  22              }
  23              catch
  24              {
  25                  this.lblShowStatus.Text = String.Empty;
  26                  this.lbShowHumidity.Text = String.Empty;
  27                  this.lbShowPressure.Text = String.Empty;
  28                  this.lbShowWind.Text = String.Empty;
  29                  this.lbShowTemperature.Text = String.Empty;
  30                  this.lblShowStatus.Text = "Error";
  31              }
  32          }
  33  
  34  
  35  
« Newer Snippets
Older Snippets »
Showing 1-2 of 2 total  RSS