谷歌分析

发布于 2024-12-10 19:10:03 字数 2080 浏览 0 评论 0原文

我只是 Google Analytic API 的初学者。
现在我正在测试这段代码。

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;
}

URL 值为

时,上层代码正确运行 <一href="https://www.google.com/analytics/feeds/data?ids=ga:xxxxxxxx&dimensions=ga:浏览器,ga:浏览器版本,ga:城市,ga:日期,ga:小时,ga:visitCount ,克a:visitorType&metrics=ga:entrances,ga:uniquePageviews&start-date=2011-09-18&end-date=2011-10-18&sort=-ga:entrances&max-results=50" rel="nofollow">https://www.google.com/analytics/feeds/data?ids=ga:xxxxxxxx&dimensions=ga:browser,ga:browserVersion,ga:city,ga:date,ga:hour, ga:访问计数t,ga:visitorType&metrics=ga:entrances,ga:uniquePageviews&start-date=2011-09-18&end-date=2011-10-18&sort=-ga:entrances&max-results=50

然后上面的代码返回正确的信息。
但是当我将 URL 值更改为

时 <一href="https://www.google.com/analytics/feeds/data?ids=ga:xxxxxxxx&dimensions=ga:pagePath,ga:浏览器,ga:浏览器版本,ga:城市,ga:日期,ga:小时,ga:访问C ount,ga:visitorType&metrics=ga:entrances,ga:uniquePageviews&start-date=2011-09-18&end-date=2011-10-18&sort=-ga:entrances&max-results=50" rel="nofollow">https://www.google.com/analytics/feeds/data?ids=ga:xxxxxxxx&dimensions=ga:pagePath,ga:浏览器,ga:浏览器版本,ga:城市,ga:日期, ga:小时,ga:vis itCount,ga:visitorType&metrics=ga:entrances,ga:uniquePageviews&start-date=2011-09-18&end-date=2011-10-18&sort=-ga:entrances&max-results=50

它给出了这个错误。

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

这两个 URL 之间唯一的区别是 ga:pagePath

请让我知道如何避免这些错误。 任何形式的建议表示赞赏。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱情眠于流年 2024-12-17 19:10:03

这就是解决办法,减少一维,就可以了。
只允许 7 个维度,您使用了 8 个。

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

ˉ厌 2024-12-17 19:10:03

如果您想了解有多少访问者访问了每个页面,则应仅包含维度 ga:pagePath。在我看来,您试图通过单个查询获取您想要的所有内容,而实际上您应该执行多个查询。您还可以在查询浏览器上测试您的查询:

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:

假面具 2024-12-17 19:10:03

首先使用 查询浏览器 检查它是否正常工作,然后检查您的代码。仅针对此问题不显示 400 错误。 可能存在身份验证问题

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文