Guida introduttiva alla libreria client .NET
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Jeff Fisher, team delle API Google Data
Agosto 2007
Introduzione
Figura 1: la soluzione Google Data API
Per molti sviluppatori, la parte più difficile di un nuovo progetto è iniziare: installare nuovi pacchetti software, configurare un ambiente di sviluppo e imparare nuove librerie. In questo articolo ho raccolto alcune istruzioni passo passo su come iniziare a utilizzare la libreria client .NET utilizzando Visual Studio 2005 per Windows o Mono per Linux e altri sistemi operativi Unix. Spero che questo ti faccia risparmiare tempo per iniziare e ti consenta di lavorare rapidamente con un po' di codice.
Visual Studio 2008
Se non hai già installato Visual Studio 2008, ti consigliamo di utilizzare Visual C# 2008 Express Edition, una versione senza costi di Visual Studio che ti consentirà di utilizzare la libreria client .NET.
Configurazione dell'ambiente
- Scarica la versione MSI più recente della libreria client da http://code.google.com/p/google-gdata/downloads/list.
- Esegui il file MSI scaricato per installare il pacchetto. Per impostazione predefinita, l'installazione verrà eseguita in "C:\Programmi\Google\Google Data API SDK\". Gli altri esempi riportati in questo articolo presuppongono che tu abbia installato la libreria client in questa posizione.
- Apri il file della soluzione denominato "Google Data API SDK" nella cartella "Google Data API SDK" del menu Start.
Compilazione ed esecuzione di esempi
- Verifica che l'esecuzione di "Build > Build Solution" venga completata senza errori.
- Per creare una build di debug, vai a "Build > Configuration Manager" e seleziona "Debug" come configurazione della soluzione attiva. Quindi seleziona "Build > Build Solution" (Compila > Compila soluzione).
- I file binari e DLL che hai appena compilato si trovano in
"C:\Program Files\Google\Google Data API SDK\Sources\Samples\"
Ad esempio, puoi eseguire l'applicazione di esempio per Calendar eseguendo "C:\Program Files\Google\Google Data API SDK\Sources\Samples\calendar\bin\Debug\Calendar.exe". Esistono anche alcune scorciatoie del menu Start per questi esempi.
Sviluppare la propria applicazione
Se vuoi sviluppare un progetto al di fuori del file della soluzione fornito dal file MSI, devi aggiungere i file DLL della libreria client come percorso di riferimento.
- Crea o apri un progetto al di fuori della soluzione Google API SDK.
- Seleziona "Aggiungi riferimento" dal menu Progetto.
- Fai clic sulla scheda Sfoglia.
- Vai alla directory Redist nell'SDK: "C:\Program Files\Google\Google Data API SDK\Redist".
- Seleziona i file DLL che verranno utilizzati dal tuo codice. Per la maggior parte dei progetti saranno necessari Google.GData.Extensions.dll e Google.GData.Client.dll, insieme al file DLL specifico per i servizi Google che utilizzi nella tua applicazione.
Nota:esiste anche un file di soluzione per le librerie client sui dispositivi mobili. Per impostazione predefinita, si trova in "C:\Programmi\Google\Google Data API SDK\Sources\Library\VS2005.mobile". Questa soluzione compilerà solo i file DLL per le librerie client.
Esecuzione dei test NUnit
Assicurarsi che i test NUnit appropriati vengano superati è un passaggio importante se apporti modifiche alle librerie client o prevedi di contribuire. Se prevedi di utilizzare le librerie client senza modifiche, in genere non è necessario eseguirle.
- Scarica il file MSI .NET 2.0 di NUnit da http://www.nunit.org/index.php?p=download.
- Installa NUnit eseguendo il file MSI. Il percorso di installazione predefinito è simile a "C:\Programmi\NUnit 2.4.8". Ti consigliamo di modificare questo percorso in qualcosa come "C:\Program Files\NUnit" per poter eseguire l'upgrade di NUnit in futuro senza dover modificare il percorso nel progetto Visual Studio.
- Vai alla directory "C:\Programmi\Google\Google Data API SDK\Sources\Library\VS2005" e apri il file della soluzione denominato "Google Data APIs".
Verrà visualizzata la procedura guidata per la conversione, poiché si tratta di un file di progetto di Visual Studio 2005. Segui i prompt o fai clic sul pulsante "Fine". Dovrebbe essere visualizzato il log delle conversioni, che può essere ignorato.
- Ora NUnit deve essere aggiunto come percorso di riferimento. Fai clic con il tasto destro del mouse sul progetto "unittests" in Esplora soluzioni a destra e seleziona "Proprietà". Ora fai clic sulla scheda "Percorsi di riferimento" nella finestra che si apre. Inserisci la posizione della sottodirectory "bin" dell'installazione di NUnit come percorso di riferimento e fai clic su "Aggiungi cartella". Ad esempio, se NUnit è installato in "C:\Programmi\NUnit\", devi inserire "C:\Programmi\NUnit\bin". Assicurati di salvare questa modifica prima di continuare.
- Segui i passaggi elencati in Compilazione ed esecuzione degli esempi per ricompilare la libreria client e i test unitari.
- Copia il file "unittests.dll.config" in "C:\Program Files\Google\Google Data API SDK\Sources\Library\unittests\" nella directory di compilazione di debug "C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\". Ricorda di modificare il file in modo da includere le informazioni appropriate per i test che stai eseguendo. Ad esempio, Base richiede una chiave API e Calendar richiede un nome utente e una password. Ti consigliamo di utilizzare un account di test senza dati attivi per evitare che le informazioni vengano eliminate dai test unitari.
- Apri NUnit dal menu Start.
- Vai a "File > Open Project" (File > Apri progetto) e seleziona il file "unittests.dll" da "C:\Program Files\Google\Google Data API SDK\Source\Library\VS2005\unittests\bin\Debug\".
- Esegui i test delle unità che ti interessano. Ricorda che per il corretto funzionamento di alcuni test è necessario impostare i parametri in unittests.dll.config. Se esegui gli stress test per determinati servizi, il tuo account di test potrebbe essere segnalato come generatore di spam e non potrai inviare contenuti ai server di Google in modo programmatico senza incontrare problemi con i CAPTCHA.
Mono
Mono è un progetto open source che consente di eseguire applicazioni client e server .NET su Linux, Solaris, Mac OS X, Windows e Unix. Offriamo un file ZIP separato della nostra libreria client per gli sviluppatori che vogliono lavorare su una di queste piattaforme.
Configurazione dell'ambiente
- Scarica l'ultima release del file ZIP della libreria client da http://code.google.com/p/google-gdata/downloads/list
- Estrai in una directory locale (ad es. "/scratch/gdata.NET")
- Utilizza la gestione dei pacchetti della tua distribuzione per installare Mono.
In alternativa, puoi scaricarlo dalla pagina http://www.mono-project.com.
- In alcune distribuzioni devi assicurarti che il file nunit.framework.dll sia collegato correttamente alla libreria mono. Se mono è stato installato in "/usr/lib/mono", assicurati che in "/usr/lib/mono/1.0" e "/usr/lib/mono/2.0" siano presenti link simbolici per nunit.framework.dll (che deve essere installato in "/usr/lib/mono/gac/nunit.framework/<someversionstring>/nunit.framework.dll").
Compilazione ed esecuzione di esempi
- Supponendo che tu abbia installato la libreria client in "/scratch/gdata.NET", passa alla directory "/scratch/gdata.NET/clients/cs".
- Modifica il Makefile a seconda della versione di .NET che vuoi utilizzare. Per .NET 1.x, utilizza
CSC=mcs
e per .NET 2.x, utilizza CSC=gmcs
.
- Esegui
make
per compilare le librerie e le applicazioni di esempio.
- Esegui
make install
se vuoi installare le DLL della libreria client nella libreria Mono.
Sviluppare la propria applicazione
Se hai eseguito un make install
dopo aver compilato la libreria client, dovresti essere in grado di includere le librerie nel tuo codice passando -r:Google.GData.Extensions.dll -r:Google.GData.Client.dll
al compilatore Mono C# insieme ai riferimenti ai file DLL di eventuali estensioni di servizio specifiche che vuoi utilizzare.
Esecuzione dei test NUnit
- Copia il file unittests.dll.config da "/scratch/gdata.NET/clients/cs/src/unittests" a "/scratch/gdata.NET/clients/cs/".
- Modifica "/scratch/gdata.NET/clients/cs/unittests.dll.config" per includere le informazioni appropriate per i test che stai eseguendo. Ad esempio, Base richiede una chiave API e Calendar richiede un nome utente e una password. Ti consiglio di utilizzare un account di test senza dati attivi per evitare che le informazioni vengano eliminate dai test unitari.
- Dopo la compilazione della libreria, nella directory "/scratch/gdata.NET/clients/cs" sarà presente un file unittests.dll. Utilizza questa DLL con il gestore di test NUnit che preferisci (nunit-console, gnunit e così via).
Conclusione
Ora dovresti essere in grado di compilare le librerie ed eseguire il codice di esempio. Ma questo è solo l'inizio. Ti consiglio di leggere la documentazione disponibile nella directory ".../clients/cs/docs" della libreria client.
Potresti anche consultare la Guida per gli sviluppatori della libreria client.NET, la pagina del progetto e la guida di riferimento, nonché il forum della libreria client .NET di Google Data.
Strumenti a cui viene fatto riferimento in questo articolo:
Buona fortuna con la tua prossima applicazione .NET.
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-27 UTC.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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,["*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\nIntroduction \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\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\nSetting 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\nCompiling 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\nDeveloping 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\nRunning 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\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\nSetting 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\nCompiling 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\nDeveloping 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\nRunning 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\nConclusion\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!"]]