|
GettingStarted
Getting started using the library
Featured In order to start developing .NET client applications which make use of the Google APIs, just follow this set of instructions.
1. Downloading the libraryWe recommend to start by downloading the zipped set of samples: Or you can fetch them straight from our source control: Once you have downloaded the file, unzip it. 2. Setting up the API ConsoleAfter you have downloaded the samples, you have to set up your API Consoles account before you can use them. The API Console can be found at: GoogleAPI Console 2.1 Enabling APIsBefore you can run a sample using a specific API, you have to enable it in here and agree to its terms of service. We recommend experimenting with the "Tasks" API as a start. 2.2 Authenticating the Sample ProjectMost of the APIs in the API Console require you to use OAuth2, or a developer key.
Important! Try to keep your client secret and developer key secret! Anyone who has access to those can potentially abuse all the privileges granted to your application. Your new Client ID and Client secret are now displayed (you will need these for the next step!). The API key is displayed in the Simple API Access section. If you have arrived at this screen, then go into the root Samples directory, and run the command below:
3. A first example: Discovery.ListAPIsAs a first example you should have a look at the "Discovery.ListAPIs" directory. This sample makes use of the "Discovery API" to show a list of all API's with which this library can be used.
You should now see a list of APIs, comparable to the output below: [..] discovery:v1: APIs Discovery Service [..] Congratulations! You have just made your first Google API call. When this ran it connected to our servers and got the latest list of services we make available. Now press any key to dismiss the console and open up Program.cs under Discovery.ListAPIs. This sample makes use of the "Discovery API" to show a list of all API's with which this library can be used. The source code for the sample is also visible below: using System;
using Google.Apis;
using Google.Apis.Data;
using Google.Apis.Samples.Helper;
namespace Discovery.ListAPIs
{
/// <summary>
/// This example uses the discovery API to list all APIs in the discovery repository.
/// http://code.google.com/apis/discovery/v1/using.html
/// </summary>
class Program
{
[STAThread]
static void Main(string[] args)
{
// Display the header and initialize the sample.
CommandLine.EnableExceptionHandling();
CommandLine.DisplayGoogleSampleHeader("Discovery API");
// Create the service.
var service = new DiscoveryService();
RunSample(service);
CommandLine.PressAnyKeyToExit();
}
private static void RunSample(DiscoveryService service)
{
// Run the request.
CommandLine.WriteAction("Executing List-request ...");
var result = service.Apis.List().Fetch();
// Display the results.
if (result.Items != null)
{
foreach (DirectoryList.ItemsData api in result.Items)
{
CommandLine.WriteResult(api.Id, api.Title);
}
}
}
}
}What is important here?
4. Whats next?
Troubleshooting"Access Not Configured" errorThis exception occurs if you try to access an API which you did not enable in your API Console. Go to the link below, and enable access to the appropriate API: API Console After changing this setting it may take some minutes for the change to take effect. System.Net.WebException when using the .NET Client Library under monoHave a look at the MonoCompability page. | |
I can't compile this code, getting error on .ExecuteRequest?().
What is the error message?
.ExecuteRequest?() returns NullReferenceException?. stack trace is as follows
Are you using the latest version of the client library? That error was fixed in rev. 7412c9ee10
the vs alert can't find using Google.Apis.Discovery; how can i you it?
Can you provide Sample code for URL shorterner?
I have problem with IService service = discovery.GetService?("v2", DiscoveryVersion?.Version_0_1, null); In discovery version is not Version_0_1 only 0_3, or 1_0. And as next, ThrowIfNull?("prarm") exception appear, when the program starts. Param is the last parameter in getService(). Thanks for help.
I have updated the sample to work with the latest release of discovery (default branch). But I recommend switching over to the GoogleApis?.CodeGen-library - we will be publishing samples for it soon.
Sorry.How can i get the reference these namespace :
using Google.Apis.Discovery; using Google.Apis.Json; using Google.Apis.Requests;
I mean how to get these dll.
The library is in alpha and dlls are not available for download yet.
You have to checkout the source as explained at http://code.google.com/p/google-api-dotnet-client/source/checkout and build the solution yourself.
I check the url.I already creat a clone.I know that just means create a server-side clone. But what does the command line mean?how to execute it to get a local copy?I can not execute it at my local? Thank you!
You need to use a Mercurial client, I'd recommend checking the getting started guide at
http://mercurial.selenic.com/guide/
Sorry.How to billing for this API? When I send a request to translate,it always give a message "day limit exceeded".So I think if I pay for the translation service ,the limitation will increase. If not,how can I increase my limitation? Thank you!
VB Samples Please.
Here's a sample code in c# that i have tried out. It does a search on public activities.
CommandLine.EnableExceptionHandling(); CommandLine.DisplayGoogleSampleHeader("PlusService API"); // Create the service. var objService= new PlusService(); objService.Key = ""; //put in uer key, not sure if it is mandatory var acts = objService.Activities.Search(); acts.Query = "super cool"; acts.MaxResults = 10; var searchResults = acts.Fetch(); if (searchResults.Items != null) { foreach (Activity feed in searchResults.Items) { CommandLine.WriteResult(feed.Title, feed.Actor);//extract any property of uer interest } }Hope this helps...
The enterCredentials.cmd file is referencing a path that is not included with the samples... EnterCredentials?\static\EnterCredentials?.exe