開始使用 .NET 用戶端程式庫
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Google Data API 團隊 Jeff Fisher
2007 年 8 月
簡介
圖 1:Google Data API 解決方案
對許多開發人員來說,新專案最困難的部分就是開始著手,包括安裝新的軟體套件、設定開發環境,以及學習新的程式庫。在本文中,我將逐步說明如何使用 Visual Studio 2005 for Windows 或 Mono for Linux 和其他 Unix 作業系統,開始使用 .NET 用戶端程式庫。希望這能協助您節省時間,快速開始使用程式碼。
Visual Studio 2008
如果您尚未安裝 Visual Studio 2008,建議使用 Visual C# 2008 Express Edition,這是 Visual Studio 的免費版本,可讓您使用 .NET 用戶端程式庫。
正在設定環境
- 從 http://code.google.com/p/google-gdata/downloads/list 下載最新 MSI 版本的用戶端程式庫。
- 執行下載的 MSI 檔案,安裝套件。根據預設,SDK 會安裝在「C:\Program Files\Google\Google Data API SDK\」中。本文中的其他範例會假設您已將用戶端程式庫安裝至這個位置。
- 在「開始」選單的「Google Data API SDK」資料夾中,開啟名為「Google Data API SDK」的解決方案檔案。
編譯及執行範例
- 確認執行「Build」>「Build Solution」時未發生任何錯誤。
- 如要建立偵錯建構作業,請依序前往「Build」>「Configuration Manager」,然後選取「Debug」做為有效解決方案設定。然後選取「Build > Build Solution」。
- 您剛編譯的二進位檔和 DLL 檔案位於「C:\Program Files\Google\Google Data API SDK\Sources\Samples\」中。舉例來說,您可以執行「C:\Program Files\Google\Google Data API SDK\Sources\Samples\calendar\bin\Debug\Calendar.exe」,執行日曆的範例應用程式。「開始」功能表也有這些範例的捷徑。
開發自己的應用程式
如要在 MSI 檔案提供的解決方案檔案以外的專案中開發,您必須將用戶端程式庫 DLL 檔案新增為參照路徑。
- 在 Google API SDK 解決方案以外建立或開啟專案。
- 從「專案」選單中選取「新增參照」。
- 按一下「瀏覽」分頁標籤。
- 前往 SDK 中的 Redist 目錄:「C:\Program Files\Google\Google Data API SDK\Redist」。
- 選取程式碼要使用的 DLL 檔案。大多數專案都需要 Google.GData.Extensions.dll 和 Google.GData.Client.dll,以及應用程式中使用的 Google 服務專屬 DLL 檔案。
注意:行動裝置上的用戶端程式庫也有解決方案檔案。預設位於「C:\Program Files\Google\Google Data API SDK\Sources\Library\VS2005.mobile」。這項解決方案只會編譯用戶端程式庫的 DLL 檔案。
執行 NUnit 測試
如果您對用戶端程式庫進行任何變更,或打算為程式庫貢獻心力,請務必通過適當的 NUnit 測試。如果您打算使用用戶端程式庫而不進行修改,通常不需要執行這些程式庫。
- 從 http://www.nunit.org/index.php?p=download 下載 NUnit 的 .NET 2.0 MSI 檔案版本。
- 執行 MSI 檔案,安裝 NUnit。預設安裝位置類似於「C:\Program Files\NUnit 2.4.8」。建議您將這個路徑變更為「C:\Program Files\NUnit」等路徑,這樣日後升級 NUnit 時,就不必變更 Visual Studio 專案中的路徑。
- 前往「C:\Program Files\Google\Google Data API SDK\Sources\Library\VS2005」目錄,然後開啟名為「Google Data APIs」的解決方案檔案。
由於這是 Visual Studio 2005 專案檔案,因此您會看到轉換精靈。按一下提示或「完成」按鈕。系統應會顯示轉換記錄,您可以忽略這項資訊。
- 現在必須將 NUnit 新增為參照路徑。在右側的「方案總管」中,以滑鼠右鍵按一下「unittests」專案,然後選取「屬性」。現在,請在開啟的視窗中點選「參考路徑」分頁。輸入 NUnit 安裝的「bin」子目錄位置做為參考路徑,然後按一下「Add Folder」(新增資料夾)。舉例來說,如果 NUnit 安裝在「C:\Program Files\NUnit\」,則應輸入「C:\Program Files\NUnit\bin」。請務必先儲存這項變更,再繼續操作。
- 按照「編譯及執行範例」一節列出的步驟,重建用戶端程式庫和單元測試。
- 將「C:\Program Files\Google\Google Data API SDK\Sources\Library\unittests\」中的「unittests.dll.config」檔案複製到偵錯建構目錄「C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\」。請記得編輯檔案,加入您要執行的測試適用的資訊。舉例來說,Base 需要 API 金鑰,而 Calendar 則需要使用者名稱和密碼。建議使用不含任何即時資料的測試帳戶,以免資訊遭單元測試刪除。
- 從「開始」功能表開啟 NUnit。
- 依序前往「File」>「Open Project」,然後從「C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\」選取「unittests.dll」檔案。
- 執行您感興趣的單元測試。請注意,部分測試需要在 unittests.dll.config 中設定參數才能運作。如果您對特定服務執行壓力測試,測試帳戶可能會遭系統標示為產生垃圾內容,且無法以程式輔助方式將內容提交至 Google 伺服器,必須通過人機驗證。
單聲道
Mono 是開放原始碼專案,可讓您在 Linux、Solaris、Mac OS X、Windows 和 Unix 上執行 .NET 用戶端和伺服器應用程式。如果開發人員想在其中一個平台上作業,我們提供用戶端程式庫的獨立 ZIP 檔案。
正在設定環境
- 從 http://code.google.com/p/google-gdata/downloads/list 下載最新版的用戶端程式庫 ZIP 檔案
- 解壓縮至本機目錄 (例如「/scratch/gdata.NET」)
- 使用發行版的套件管理工具安裝 Mono。
您也可以前往 http://www.mono-project.com 下載。
- 在某些發行版本中,您必須確保 nunit.framework.dll 檔案已正確連結至 Mono 程式庫。如果 Mono 安裝在「/usr/lib/mono」,請確認「/usr/lib/mono/1.0」和「/usr/lib/mono/2.0」中是否有 nunit.framework.dll 的符號連結 (應安裝在「/usr/lib/mono/gac/nunit.framework/<someversionstring>/nunit.framework.dll」中)。
編譯及執行範例
- 假設您將用戶端程式庫安裝至「/scratch/gdata.NET」,請變更為「/scratch/gdata.NET/clients/cs」目錄。
- 視要使用的 .NET 版本而定,編輯 Makefile。如果是 .NET 1.x,請使用
CSC=mcs
;如果是 .NET 2.x,請使用 CSC=gmcs
。
- 執行
make
編譯程式庫和範例應用程式。
- 如要將用戶端程式庫 DLL 安裝到 Mono 程式庫,請執行
make install
。
開發自己的應用程式
如果您在編譯用戶端程式庫後執行 make install
,應該就能將程式庫納入自己的程式碼中,方法是將 -r:Google.GData.Extensions.dll -r:Google.GData.Client.dll
傳遞至 Mono C# 編譯器,並參照您要使用的任何特定服務擴充功能的 DLL 檔案。
執行 NUnit 測試
- 將 unittests.dll.config 檔案從「/scratch/gdata.NET/clients/cs/src/unittests」複製到「/scratch/gdata.NET/clients/cs/」。
- 編輯「/scratch/gdata.NET/clients/cs/unittests.dll.config」,加入您要執行的測試適用的資訊。舉例來說,Base 需要 API 金鑰,而 Calendar 則需要使用者名稱和密碼。建議您使用不含任何即時資料的測試帳戶,以免單元測試刪除資訊。
- 程式庫編譯完成後,「/scratch/gdata.NET/clients/cs」中會出現 unittests.dll 檔案。搭配您選擇的 NUnit 測試管理工具 (nunit-console、gnunit 等) 使用這個 DLL。
結論
現在您應該可以編譯程式庫並執行程式碼範例。不過,這只是開始。建議您詳閱用戶端程式庫「.../clients/cs/docs」目錄中的說明文件。您也可以查看 .NET 用戶端程式庫開發人員指南、專案頁面和參考指南,以及 Google Data .NET 用戶端程式庫論壇。
本文提及的工具:
祝您下一個 .NET 應用程式開發順利!
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[null,null,["上次更新時間:2025-07-27 (世界標準時間)。"],[[["\u003cp\u003eThis guide provides step-by-step instructions for setting up and using the Google Data .NET client library with either Visual Studio 2008 or Mono.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can use this library to interact with various Google services like Calendar by compiling and running provided sample applications or by developing their own applications.\u003c/p\u003e\n"],["\u003cp\u003eThe guide includes details on compiling the library, running provided unit tests for verifying functionality, and configuring the development environment for both Windows and Unix-based systems.\u003c/p\u003e\n"],["\u003cp\u003eAdditional resources such as the .NET Client Library Developer's Guide and project forums are available for further assistance.\u003c/p\u003e\n"]]],[],null,["# Getting Started with the .NET Client Library\n\n*Jeff Fisher, Google Data APIs team\nAugust 2007*\n\n- [Introduction](#introduction)\n- [Visual Studio 2008](#vs2005)\n - [Setting up your environment](#vssetup)\n - [Compiling and running samples](#vscompile)\n - [Developing your own application](#vsdevelop)\n - [Running the NUnit tests](#vsnunit)\n- [Mono](#mono)\n - [Setting up your environment](#monosetup)\n - [Compiling and running samples](#monocompile)\n - [Developing your own application](#monodevelop)\n - [Running the NUnit tests](#mononunit)\n- [Conclusion](#conclusion)\n\n### Introduction\n\n\u003cbr /\u003e\n\n**Figure 1: The Google Data API solution**\n\nFor 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.\n\nVisual Studio 2008\n------------------\n\nIf you do not already have Visual Studio 2008 installed, you may want to consider using [Visual C# 2008 Express Edition](http://msdn.microsoft.com/en-us/library/orm-9780596521066-01-02.aspx), a free version of Visual Studio that will allow you to work with the .NET client library.\n\n### Setting up your environment\n\n1. Download the latest MSI release of the client library from [http://code.google.com/p/google-gdata/downloads/list](//code.google.com/p/google-gdata/downloads/list).\n2. 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.\n3. Open the solution file called \"Google Data API SDK\" in the \"Google Data API SDK\" folder in the Start Menu.\n\n### Compiling and running samples\n\n1. Verify that running \"Build \\\u003e Build Solution\" completes without any errors.\n2. To create a Debug build go to \"Build \\\u003e Configuration Manager\" and select \"Debug\" as the active solution configuration. Then select \"Build \\\u003e Build Solution\".\n3. 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.\n\n### Developing your own application\n\nIf 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.\n\n1. Create or open a project outside of the Google API SDK solution.\n2. Select \"Add Reference\" from the Project menu.\n3. Click on the Browse tab.\n4. Navigate to the Redist directory in the SDK: \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\Redist\".\n5. 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.\n\n**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.\n\n### Running the NUnit tests\n\nMaking 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.\n\n1. Download the .NET 2.0 MSI file release of NUnit from \u003chttp://www.nunit.org/index.php?p=download\u003e.\n2. 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.\n3. 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.\n4. 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.\n5. Follow the steps listed in [Compiling and running samples](#vscompile) to rebuild the client library and the unit tests.\n6. 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.\n7. Open NUnit from the Start Menu.\n8. Go to \"File \\\u003e Open Project\" and select the \"unittests.dll\" file from \"C:\\\\Program Files\\\\Google\\\\Google Data API SDK\\\\Source\\\\Library\\\\VS2005\\\\unittests\\\\bin\\\\Debug\\\\\".\n9. 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.\n\nMono\n----\n\nMono 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.\n\n### Setting up your environment\n\n1. Download the latest ZIP file release of the client library from [http://code.google.com/p/google-gdata/downloads/list](//code.google.com/p/google-gdata/downloads/list)\n2. Extract to a local directory (e.g. \"/scratch/gdata.NET\")\n3. Use your distribution's package management to install Mono. Alternatively, you can download it from \u003chttp://www.mono-project.com\u003e.\n4. 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/\\\u003csomeversionstring\\\u003e/nunit.framework.dll\").\n\n### Compiling and running samples\n\n1. Assuming you installed the client library to \"/scratch/gdata.NET\", change to the \"/scratch/gdata.NET/clients/cs\" directory.\n2. 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`.\n3. Run `make` to compile the libraries and sample applications.\n4. Execute `make install` if you want to install the client library DLLs into the Mono library.\n\n### Developing your own application\n\nIf 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.\n\n### Running the NUnit tests\n\n1. Copy the unittests.dll.config file from \"/scratch/gdata.NET/clients/cs/src/unittests\" to \"/scratch/gdata.NET/clients/cs/\".\n2. 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.\n3. 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.).\n\n### Conclusion\n\nNow 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.\nYou might also want to check out the [.NET Client Library Developer's Guide](/gdata/client-cs), the [project page](http://code.google.com/p/google-gdata/) and [reference guide](http://google-gdata.googlecode.com/svn/docs/Index.html), and the [Google Data .NET client library forum](http://groups.google.com/group/gdata-dotnet-client-library).\n\nTools referenced in this article:\n\n- [Mono Project](http://www.mono-project.com/Main_Page)\n- [Visual Studio](http://msdn2.microsoft.com/en-us/vstudio/default.aspx)\n- [Visual C# 2008 Express Edition](http://msdn.microsoft.com/en-us/library/orm-9780596521066-01-02.aspx)\n- [NUnit](http://www.nunit.org/)\n\nGood luck on your next .NET application!"]]