Error in Newtonsoft.Json.Net35 using the new client libraries

364 views
Skip to first unread message

Max Eriksson

unread,
Jan 2, 2012, 4:45:42 PM1/2/12
to google-analytics...@googlegroups.com
Hi

I'm trying to use the latest client libraries to access v3 of the google analytics api. A request to the management api like the one below works fine.

var results = service.Management.Accounts.List().Fetch();

But when I try to request the Report api with the following code:

var query = service.Report.Get("2012-01-01", "2011-01-01", "ga:totalEvents", "ga:XXXXXXX");
query.Dimensions = "ga:eventCategory";
query.Filters = "ga:eventCategory==ViewPorts.V1";
var res = query.Fetch();

I get the following error:
Error converting value "ga:eventCategory" to type 'System.Collections.Generic.IList`1[System.String]'.

If I remove the dimensions and filters from the query above, i.e change the code to:
var query = service.Report.Get("2012-01-01", "2011-01-01", "ga:totalEvents", "ga:XXXXXXX");
var res = query.Fetch();

Everything works fine!??

I'm I doing something wrong here or is there a bug in the .Net client libraries?

Max Eriksson

unread,
Jan 3, 2012, 11:09:58 AM1/3/12
to google-analytics-api - GA Data Export API

Ok. I think that I found the problem.

The code that doesn't work above results in the following request to
the analytics api:
https://www.googleapis.com/analytics/v3/data/ga?alt=json&key=XXXX&prettyPrint=false&dimensions=ga%3AeventLabel&end-date=2012-01-03&filters=ga%3AeventCategory%3D%3DPropertyDetails.V1%3Bga%3AeventAction%3D%3DPropertyDetail.Show%3Bga%3AeventLabel%3D~.*(%2F.*)%7B2%7D%2F%5B0-9%5D*%2F&ids=ga%3AXXXXXX&metrics=ga%3AtotalEvents&sort=-ga%3AtotalEvents&start-date=2011-12-04

In the repose for the request above the query element has the
following json structure:
"query":
{
"start-date":"2011-12-04",
"end-date":"2012-01-03",
"ids":"ga:XXXXX",
"dimensions":"ga:eventLabel",
"metrics":["ga:totalEvents"],
"sort":["-ga:totalEvents"],

"filters":"ga:eventCategory==PropertyDetails.V1;ga:eventAction==PropertyDetail.Show;ga:eventLabel=~.*(/.*)
{2}/[0-9]*/",
"start-index":1,
"max-results":1000
}

Notice that the value of the "dimensions" property is declared as
"ga:eventLabel" and the property
Google.Apis.Analytics.v3.Data.GaReport.QueryData.Dimensions, in
the .Net client libraries, is declared as a
System.Collections.Generic.IList<string>. I.e. the jsonconverter
obviously fails to convert the string "ga:eventLabel" to
System.Collections.Generic.IList<string>. If I compare the json
declaration of the "metrics" property, ["ga:totalEvents"] (declared as
an array), which also is declared as a
System.Collections.Generic.IList<string> in the client libraries, my
conclusion is that there is a bug in the analytics v3 api or in the
client libraries.

If it’s a bug in the analytics api, which I think, the "dimensions"
property should be corrected and declared as an array, i.e.
["ga:eventLabel"] in the json response.
If it’s a bug in the client libraries, the property
Google.Apis.Analytics.v3.Data.GaReport.QueryData.Dimensions should be
declares as a string.

Comments?

Jegonet

unread,
Jan 6, 2012, 11:16:38 AM1/6/12
to google-analytics-api - GA Data Export API
Hi Max,

Yes, it is an error in the .Net library, however you can download the
Google Analytics API .NET Library source code and fix it, I must to
do it to solve this.

Yo can download this DLL from http://code.google.com/p/google-api-dotnet-client/wiki/APIs#Google_Analytics_API
(Link Source)

Delete the DLL reference on the project, and put the cs source code in
the project (you may put it in the root folder).

So changes are in line 579:
private String dimensions;

And line 601:
public virtual String Dimensions {

Best Regards,

Jorge Gantiva,
Colombia, Bogotá D.C.

Bob Myers

unread,
Jan 19, 2012, 6:02:33 PM1/19/12
to google-analytics...@googlegroups.com
Any one know if Google has any plans to actually fix this?

Max Eriksson

unread,
Jan 20, 2012, 2:10:31 AM1/20/12
to google-analytics...@googlegroups.com
+1.

A very, very good question. 

Grant Means

unread,
Feb 13, 2012, 6:42:40 PM2/13/12
to google-analytics-api - GA Data Export API
This doesn't seem like a bug in the library rather the API service.
Unless I am mistaken, since you can pass in multiple dimensions with a
query, it should always return that as an array.

If you make the change Jegonet proposes you are forever limited to a
single dimension being passed.

On Jan 6, 11:16 am, Jegonet <jego...@gmail.com> wrote:
> Hi Max,
>
> Yes, it is an error in the .Net library, however you can download the
> Google Analytics API .NET Library source code  and fix it, I must to
> do it to solve this.
>
> Yo can download this DLL fromhttp://code.google.com/p/google-api-dotnet-client/wiki/APIs#Google_An...
Reply all
Reply to author
Forward
0 new messages