Google Data APIs

Getting Started with the .NET Client Library

Jeff Fisher, Google Data APIs team
August 2007

Introduction

The Google Data API solution
Figure 1: The Google Data API solution

For many developers, the most difficult part of a new project is getting the ball rolling-installing new software packages, configuring a development environment, and learning new libraries. In this article, I have pulled together some step-by-step instructions for how to begin with the .NET client library using either Visual Studio 2005 for Windows or Mono for Linux and other Unix operating systems. It is my hope that this will save you some time in getting started and let you quickly start working with some code.

Visual Studio 2008

If you do not already have Visual Studio 2008 installed, you may want to consider using Visual C# 2008 Express Edition, a free version of Visual Studio that will allow you to work with the .NET client library.

Setting up your environment

  1. Download the latest MSI release of the client library from http://code.google.com/p/google-gdata/downloads/list.
  2. Run the downloaded MSI file to install the package. It will install to "C:\Program Files\Google\Google Data API SDK\" by default. Further examples in this article will assume you installed the client library to this location.
  3. Open the solution file called "Google Data API SDK" in the "Google Data API SDK" folder in the Start Menu.

Compiling and running samples

  1. Verify that running "Build > Build Solution" completes without any errors.
  2. To create a Debug build go to "Build > Configuration Manager" and select "Debug" as the active solution configuration. Then select "Build > Build Solution".
  3. The binaries and DLL files you have just compiled can be found in "C:\Program Files\Google\Google Data API SDK\Sources\Samples\" For example, you can run the sample application for Calendar by executing "C:\Program Files\Google\Google Data API SDK\Sources\Samples\calendar\bin\Debug\Calendar.exe". There are also some Start Menu shortcuts to these samples.

Developing your own application

If you want to develop in a project outside of the solution file provided by the MSI file, you need to add the client library DLL files as a reference path.

  1. Create or open a project outside of the Google API SDK solution.
  2. Select "Add Reference" from the Project menu.
  3. Click on the Browse tab.
  4. Navigate to the Redist directory in the SDK: "C:\Program Files\Google\Google Data API SDK\Redist".
  5. Select the DLL files that will be used by your code. Google.GData.Extensions.dll and Google.GData.Client.dll will be needed for most projects, along with the DLL file specific to the Google service(s) you are using in your application.

Note: There is also a solution file for client libraries on Mobile devices. It is found in "C:\Program Files\Google\Google Data API SDK\Sources\Library\VS2005.mobile" by default. This solution will only compile the DLL files for the client libraries.

Running the NUnit tests

Making sure the appropriate NUnit tests pass is an important step if you make any changes to the client libraries or plan to contribute to them. If you plan to use the client libraries without modifications then there is normally no need to run them.

  1. Download the .NET 2.0 MSI file release of NUnit from http://www.nunit.org/index.php?p=download.
  2. Install NUnit by running the MSI file. The default install location is similar to "C:\Program Files\NUnit 2.4.8". You may wish to change this to something like "C:\Program Files\NUnit" so you can upgrade NUnit in the future without having to change the path in your Visual Studio project.
  3. Go to the "C:\Program Files\Google\Google Data API SDK\Sources\Library\VS2005" directory and open the solution file named "Google Data APIs". You will see the Conversion Wizard since this is a Visual Studio 2005 project file. Either click through the prompts or simply click on the "Finish" button. It should display the conversion log, which can be ignored.
  4. Now NUnit must be added as a reference path. Right click on the "unittests" project in the Solution Explorer on the right and select "Properties". Now click on the "Reference Paths" tab within the window that opens. Enter in the location of the "bin" subdirectory of the NUnit installation as a reference path and click "Add Folder". For example, if NUnit is installed to "C:\Program Files\NUnit\", one would enter "C:\Program Files\NUnit\bin". Be sure to save this change before continuing.
  5. Follow the steps listed in Compiling and running samples to rebuild the client library and the unit tests.
  6. Copy the "unittests.dll.config" file in "C:\Program Files\Google\Google Data API SDK\Sources\Library\unittests\" to your debug build directory "C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\". Remember to edit the file to include the appropriate information for the tests you are running. For example, Base requires an API key and Calendar requires a username and password. It is recommended to use a test account without any live data to avoid having information deleted by the unit tests.
  7. Open NUnit from the Start Menu.
  8. Go to "File > Open Project" and select the "unittests.dll" file from "C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\".
  9. Run the unit tests you are interested in. Remember that certain tests require parameters be set in unittests.dll.config to work. If you run the stress tests for certain services you may have your test account flagged as generating spam and be unable to programmatically submit content to Google servers without encountering CAPTCHA challenges.

Mono

Mono is an open source project that allows you to run .NET client and server applications on Linux, Solaris, Mac OS X, Windows, and Unix. We offer a separate ZIP file of our client library for developers who want to work on one of these platforms.

Setting up your environment

  1. Download the latest ZIP file release of the client library from http://code.google.com/p/google-gdata/downloads/list
  2. Extract to a local directory (e.g. "/scratch/gdata.NET")
  3. Use your distribution's package management to install Mono. Alternatively, you can download it from http://www.mono-project.com.
  4. In some distributions you have to make sure that the nunit.framework.dll file is properly linked into the mono library. If mono was installed to "/usr/lib/mono", then ensure that there are symbolic links in "/usr/lib/mono/1.0" and "/usr/lib/mono/2.0" for nunit.framework.dll (which should be installed in "/usr/lib/mono/gac/nunit.framework/<someversionstring>/nunit.framework.dll").

Compiling and running samples

  1. Assuming you installed the client library to "/scratch/gdata.NET", change to the "/scratch/gdata.NET/clients/cs" directory.
  2. Edit the Makefile depending on what version of .NET you wish to use. For .NET 1.x, use CSC=mcs and for .NET 2.x, use CSC=gmcs.
  3. Run make to compile the libraries and sample applications.
  4. Execute make install if you want to install the client library DLLs into the Mono library.

Developing your own application

If you executed a make install after compiling the client library, you should be able to include the libraries in your own code by passing -r:Google.GData.Extensions.dll -r:Google.GData.Client.dll to the Mono C# compiler along with references to the DLL files of any specific service extensions you wish to use.

Running the NUnit tests

  1. Copy the unittests.dll.config file from "/scratch/gdata.NET/clients/cs/src/unittests" to "/scratch/gdata.NET/clients/cs/".
  2. Edit "/scratch/gdata.NET/clients/cs/unittests.dll.config" to include the appropriate information for the tests you are running. For example, Base requires an API key and Calendar requires a username and password. I recommend using a test account without any live data to avoid having information deleted by the unit tests.
  3. After compiling the library there will be a unittests.dll file in "/scratch/gdata.NET/clients/cs". Use this DLL with your NUnit test manager of choice (nunit-console, gnunit, etc.).

Conclusion

Now you should be able to compile the libraries and run the sample code. This is only the beginning, however. I encourage you to read through the documentation found in the ".../clients/cs/docs" directory of the client library. You might also want to check out the .NET Client Library Developer's Guide, the project page and reference guide, and the Google Data .NET client library forum.

Tools referenced in this article:

Good luck on your next .NET application!

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.