google-analytics-api

Re: .NET application using GData API - need to use API key?


Graham Stephen Mar 16, 2012 2:37 AM
Posted in group: Google Analytics Reporting API
Here is a bit more of my code:

// Authenticate with the Analytics Service
AnalyticsService service = new AnalyticsService("AnalyticsDataExtractor");
service.setUserCredentials(username, password);

// Formulate the Query
DataQuery query = new DataQuery(dataFeedUrl);
query.Ids = profileId;
query.GAStartDate = dtpFrom.Value.ToString("yyyy-MM-dd");
query.GAEndDate = dtpTo.Value.ToString("yyyy-MM-dd");

// Query for overall statistics
query.Dimensions = "";
query.Metrics = "ga:visitors,ga:visits,ga:newVisits,ga:pageviews,ga:pageviewsPerVisit,ga:avgTimeOnSite";
OutputDimensionsAndMetrics(service.Query(query));

So are you saying that I need to append ?key=... to the dataFeedUrl passed in to the DataQuery constructor?  I have tried that and retrieving data still works okay, but I am a little suspicious as to whether it is actually being read or not as using an invalid API key did not provoke any error to be raised.

Can you confirm that (browser) API keys are actually required for Windows Forms apps, and if so what the recommended method of specifying them via the .net client library object properties is?

Many thanks.

On Thursday, 15 March 2012 17:44:07 UTC, Nick wrote:
Hi,

You just need to add a new 'key' query parameter to each request. So:

http://......?ids=ga:xxxx&key=apiKey

where apiKey is what you get once you register a project in the Google APIs console.

-Nick



On Thursday, March 15, 2012 5:15:54 AM UTC-7, Graham Stephen wrote:
I've just started building a .net windows forms application to merge analytics data (retrieved using the .net GData API client library) with other business data.  Having looked at the Analytics samples in the SDK I have a quick prototype up and running.  Before running any queries, this does the following:

// Authenticate with the Analytics Service
AnalyticsService service = new AnalyticsService("AnalyticsDataExtractor");
service.setUserCredentials(username, password);

where the username and password are appropriate for one of several accounts configured in the application.

I've read that to enjoy the full quota, applications have to be registered.  What I have not been able to find out is how to identify the application (using the API key?) to the server using the .net client library.

Does this need to be done, and if so how?

Thanks very much in advance for any help.