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

237 views
Skip to first unread message

Graham Stephen

unread,
Mar 15, 2012, 8:15:54 AM3/15/12
to google-analytics...@googlegroups.com
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.

Nick

unread,
Mar 15, 2012, 1:44:07 PM3/15/12
to google-analytics...@googlegroups.com
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

Graham Stephen

unread,
Mar 16, 2012, 5:37:30 AM3/16/12
to google-analytics...@googlegroups.com
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.

Pete

unread,
Mar 16, 2012, 11:21:34 AM3/16/12
to google-analytics...@googlegroups.com
Log in to the APIs Console and check the Reports pane for the Project associated with your Key. It will show you how many requests have been made. It should be > 0 if it's working.

https://code.google.com/apis/console

Graham Stephen

unread,
Mar 21, 2012, 9:43:16 AM3/21/12
to google-analytics...@googlegroups.com
Thanks Pete.  Unfortunately, as I feared. there are 0 requests recorded.

Is there not anyone else using the .NET client library out there?

Rmon

unread,
Apr 3, 2012, 2:10:54 AM4/3/12
to google-analytics-api - GA Data Export API
I have found the same thing. It looks like when you use the
ClientLogin you can record the usage and also enjoy the 50,000 calls
per day.
Reply all
Reply to author
Forward
0 new messages