1
votes

I am just beginner for Google Analytic API.
Now i am testing this code.

public static string HttpGetRequest(string url, string[] headers)
{
    String result;
    WebRequest request = WebRequest.Create(url);
    if (headers.Length > 0)
    {
        foreach (var header in headers)
        {
            request.Headers.Add(header);
        }
    }
    WebResponse response = request.GetResponse();
    using (var sr = new StreamReader(response.GetResponseStream()))
    {
        result = sr.ReadToEnd();
        sr.Close();
    }
    return result;
}

Upper code run correctly when URL value is

https://www.google.com/analytics/feeds/data?ids=ga:xxxxxxxx&dimensions=ga:browser,ga:browserVersion,ga:city,ga:date,ga:hour,ga:visitCount,ga:visitorType&metrics=ga:entrances,ga:uniquePageviews&start-date=2011-09-18&end-date=2011-10-18&sort=-ga:entrances&max-results=50

And then this upper code return correct information.
But when i change URL value to

https://www.google.com/analytics/feeds/data?ids=ga:xxxxxxxx&dimensions=ga:pagePath,ga:browser,ga:browserVersion,ga:city,ga:date,ga:hour,ga:visitCount,ga:visitorType&metrics=ga:entrances,ga:uniquePageviews&start-date=2011-09-18&end-date=2011-10-18&sort=-ga:entrances&max-results=50

It give this error.

The remote server returned an error: (400) Bad Request. 

The only thing differences between these two URL is ga:pagePath.

Please let me know how could I avoid these error. Any kind of suggestion is appreciated.

3
Are you sure ga:pagePath is even valid the error would indicate its not. - Security Hound
sorry Ramhound, i am not clear what you would like to say. - Frank Myat Thu
I am so sure that this error occur only when I put URL value to ga:pagePath. - Frank Myat Thu
Don't you need to include a ga:pagePath filter too? - Rup
I want to see information about which pages of my web site users view. - Frank Myat Thu

3 Answers

1
votes

This is the solution, reduce one dimension, and it will work. Only 7 dimensions are allowed, you used 8.

0
votes

If you want to see how many visitors visited each page you should include only the dimension ga:pagePath. Seems like to me that you're trying to fetch everything you want with a single query when in fact you should be doing multiple queries. Also you can test your queries on the query explorer:

0
votes

First check with query explorer, if it's working or not, then check your code. 400 error is not shown only for this problem. May be a problem in authentication