Primeiros passos com a biblioteca de cliente .NET
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Jeff Fisher, equipe de APIs de dados do Google
Agosto de 2007
Introdução
Figura 1: a solução da API Google Data
Para muitos desenvolvedores, a parte mais difícil de um novo projeto é começar: instalar novos pacotes de software, configurar um ambiente de desenvolvimento e aprender novas bibliotecas. Neste artigo, reuni algumas instruções detalhadas sobre como começar a usar a biblioteca de cliente .NET com o Visual Studio 2005 para Windows ou o Mono para Linux e outros sistemas operacionais Unix. Espero que isso poupe seu tempo para começar e permita que você trabalhe rapidamente com algum código.
Visual Studio 2008
Se você ainda não tiver o Visual Studio 2008 instalado, considere usar o Visual C# 2008 Express Edition (em inglês), uma versão sem custo financeiro do Visual Studio que permite trabalhar com a biblioteca de cliente .NET.
Como configurar o ambiente
- Faça o download da versão MSI mais recente da biblioteca de cliente em http://code.google.com/p/google-gdata/downloads/list.
- Execute o arquivo MSI baixado para instalar o pacote. Por padrão, ele será instalado em "C:\Program Files\Google\Google Data API SDK\". Outros exemplos neste artigo vão presumir que você instalou a biblioteca de cliente nesse local.
- Abra o arquivo de solução chamado "SDK da API Google Data" na pasta "SDK da API Google Data" no menu Iniciar.
Compilar e executar exemplos
- Verifique se a execução de "Build > Build Solution" é concluída sem erros.
- Para criar um build de depuração, acesse "Build > Configuration Manager" e selecione "Debug" como a configuração de solução ativa. Em seguida, selecione "Build > Build Solution".
- Os arquivos binários e DLL que você acabou de compilar podem ser encontrados em "C:\Program Files\Google\Google Data API SDK\Sources\Samples\". Por exemplo, você pode executar o aplicativo de amostra do Google Agenda executando "C:\Program Files\Google\Google Data API SDK\Sources\Samples\calendar\bin\Debug\Calendar.exe". Também há alguns atalhos do menu Iniciar para essas amostras.
Como desenvolver seu próprio aplicativo
Se você quiser desenvolver em um projeto fora do arquivo de solução fornecido pelo arquivo MSI, adicione os arquivos DLL da biblioteca de cliente como um caminho de referência.
- Crie ou abra um projeto fora da solução do SDK de APIs do Google.
- Selecione "Adicionar referência" no menu "Projeto".
- Clique na guia "Procurar".
- Acesse o diretório "Redist" no SDK: "C:\Arquivos de Programas\Google\Google Data API SDK\Redist".
- Selecione os arquivos DLL que serão usados pelo seu código. Google.GData.Extensions.dll e Google.GData.Client.dll serão necessários para a maioria dos projetos, além do arquivo DLL específico dos Serviços do Google que você está usando no aplicativo.
Observação:também há um arquivo de solução para bibliotecas de cliente em dispositivos móveis. Por padrão, ele está em "C:\Program Files\Google\Google Data API SDK\Sources\Library\VS2005.mobile". Essa solução vai compilar apenas os arquivos DLL para as bibliotecas de cliente.
Executar os testes do NUnit
Garantir que os testes NUnit adequados sejam aprovados é uma etapa importante se você fizer alguma mudança nas bibliotecas de cliente ou planejar contribuir com elas. Se você planeja usar as bibliotecas de cliente sem modificações, normalmente não é necessário executá-las.
- Faça o download da versão do arquivo MSI do .NET 2.0 do NUnit em http://www.nunit.org/index.php?p=download.
- Execute o arquivo MSI para instalar o NUnit. O local de instalação padrão é semelhante a "C:\Arquivos de Programas\NUnit 2.4.8". Você pode mudar isso para algo como "C:\Program Files\NUnit" para poder fazer upgrade do NUnit no futuro sem precisar mudar o caminho no projeto do Visual Studio.
- Acesse o diretório "C:\Program Files\Google\Google Data API SDK\Sources\Library\VS2005" e abra o arquivo de solução chamado "Google Data APIs".
O assistente de conversão vai aparecer porque este é um arquivo de projeto do Visual Studio 2005. Clique nos comandos ou simplesmente no botão "Concluir". Ele vai mostrar o registro de conversão, que pode ser ignorado.
- Agora o NUnit precisa ser adicionado como um caminho de referência. Clique com o botão direito do mouse no projeto "unittests" no Solution Explorer à direita e selecione "Properties". Agora clique na guia "Caminhos de referência" na janela que abrir. Insira o local do subdiretório "bin" da instalação do NUnit como um caminho de referência e clique em "Adicionar pasta". Por exemplo, se o NUnit estiver instalado em "C:\Program Files\NUnit\", insira "C:\Program Files\NUnit\bin". Salve essa mudança antes de continuar.
- Siga as etapas listadas em Compilar e executar exemplos para recriar a biblioteca de cliente e os testes de unidade.
- Copie o arquivo "unittests.dll.config" em "C:\Program Files\Google\Google Data API SDK\Sources\Library\unittests\" para o diretório de build de depuração "C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\". Não se esqueça de editar o arquivo para incluir as informações adequadas aos testes que você está executando. Por exemplo, o Base exige uma chave de API, e o Calendar exige um nome de usuário e uma senha. Recomendamos usar uma conta de teste sem dados ativos para evitar que as informações sejam excluídas pelos testes de unidade.
- Abra o NUnit no menu Iniciar.
- Acesse "File > Open Project" e selecione o arquivo "unittests.dll" em "C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\".
- Execute os testes de unidade que você quer. Lembre-se de que alguns testes exigem que os parâmetros sejam definidos em unittests.dll.config para funcionar. Se você executar os testes de estresse em determinados serviços, sua conta de teste poderá ser sinalizada como geradora de spam, e não será possível enviar conteúdo de forma programática aos servidores do Google sem enfrentar desafios de CAPTCHA.
Mono
O Mono é um projeto de código aberto que permite executar aplicativos cliente e servidor .NET no Linux, Solaris, Mac OS X, Windows e Unix. Oferecemos um arquivo ZIP separado da nossa biblioteca de cliente para desenvolvedores que querem trabalhar em uma dessas plataformas.
Como configurar o ambiente
- Faça o download da versão mais recente do arquivo ZIP da biblioteca de cliente em http://code.google.com/p/google-gdata/downloads/list
- Extraia para um diretório local (por exemplo, "/scratch/gdata.NET")
- Use o gerenciamento de pacotes da sua distribuição para instalar o Mono.
Ou faça o download em http://www.mono-project.com.
- Em algumas distribuições, é necessário verificar se o arquivo nunit.framework.dll está vinculado corretamente à biblioteca mono. Se o mono foi instalado em "/usr/lib/mono", verifique se há links simbólicos em "/usr/lib/mono/1.0" e "/usr/lib/mono/2.0" para nunit.framework.dll, que deve estar instalado em "/usr/lib/mono/gac/nunit.framework/<someversionstring>/nunit.framework.dll".
Compilar e executar exemplos
- Supondo que você tenha instalado a biblioteca de cliente em "/scratch/gdata.NET", mude para o diretório "/scratch/gdata.NET/clients/cs".
- Edite o Makefile dependendo da versão do .NET que você quer usar. Para .NET 1.x, use
CSC=mcs
e para .NET 2.x, use CSC=gmcs
.
- Execute
make
para compilar as bibliotecas e os aplicativos de amostra.
- Execute
make install
se quiser instalar as DLLs da biblioteca de cliente na biblioteca Mono.
Como desenvolver seu próprio aplicativo
Se você executou um make install
depois de compilar a biblioteca de cliente, poderá incluir as bibliotecas no seu próprio código transmitindo -r:Google.GData.Extensions.dll -r:Google.GData.Client.dll
ao compilador Mono C# junto com referências aos arquivos DLL de qualquer extensão de serviço específica que você queira usar.
Executar os testes do NUnit
- Copie o arquivo unittests.dll.config de "/scratch/gdata.NET/clients/cs/src/unittests" para "/scratch/gdata.NET/clients/cs/".
- Edite "/scratch/gdata.NET/clients/cs/unittests.dll.config" para incluir as informações adequadas aos testes que você está executando. Por exemplo, o Base exige uma chave de API, e o Calendar exige um nome de usuário e uma senha. Recomendamos usar uma conta de teste sem dados ativos para evitar que as informações sejam excluídas pelos testes de unidade.
- Depois de compilar a biblioteca, um arquivo unittests.dll será criado em "/scratch/gdata.NET/clients/cs". Use essa DLL com o gerenciador de testes NUnit de sua escolha (nunit-console, gnunit etc.).
Conclusão
Agora você pode compilar as bibliotecas e executar o exemplo de código. Mas isso é só o começo. Recomendamos que você leia a documentação encontrada no diretório ".../clients/cs/docs" da biblioteca de cliente.
Confira também o guia do desenvolvedor da biblioteca de cliente.NET, a página do projeto e o guia de referência, além do fórum da biblioteca de cliente .NET do Google Data.
Ferramentas mencionadas neste artigo:
Boa sorte no seu próximo aplicativo .NET!
Exceto em caso de indicação contrária, o conteúdo desta página é licenciado de acordo com a Licença de atribuição 4.0 do Creative Commons, e as amostras de código são licenciadas de acordo com a Licença Apache 2.0. Para mais detalhes, consulte as políticas do site do Google Developers. Java é uma marca registrada da Oracle e/ou afiliadas.
Última atualização 2025-07-27 UTC.
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Não contém as informações de que eu preciso","missingTheInformationINeed","thumb-down"],["Muito complicado / etapas demais","tooComplicatedTooManySteps","thumb-down"],["Desatualizado","outOfDate","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Problema com as amostras / o código","samplesCodeIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-07-27 UTC."],[[["\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!"]]