谷歌Analytics(分析)API - 通过.NET过滤 - 因此关闭! [英] Google Analytics API - Filtering via .NET - So Close!
问题描述
大家下午好!我一直在寻找计算器和网络约24小时,现在,我还没有找到一个答案。我希望我失去了一些东西简单,一个经验丰富的API,用户可以点出我。
我查询使用他们的.NET库的谷歌Analytics(分析)API。此请求如下:
<$p$p><$c$c>https://www.google.com/analytics/feeds/data?start-index=1&max-results=500&dimensions=ga:date&end-date=2011-01-06&ids=ga:________&metrics=ga:visitors,ga:visits&start-date=2011-01-06
...但我想筛选结果。我已经尝试了一个非常简单的过滤器,它不需要URL编码:
过滤器= GA:城市@Minsk
我得到的是令人抓狂模糊的400错误的请求的错误。我使用equals运营商处获得相同的结果:
DataQuery查询=新DataQuery(URL);
...
query.Filters =GA:城市==明斯克
同上,如果我连接code中的等号的%3D。这被转换为GA:全市%253D%253DMinsk,根据错误消息。我试过单引号明斯克,而双引号它;没有运气。
我难倒。有任何想法吗?谢谢!
发现了它。事实证明,过滤器必须是兼容与pssed在查询的维度和指标实际上EX $ P $。删除GA:游客让我申请我最需要的过滤器,但GA的组合:pagePath和GA:活动不与GA不允许:参观......出于某种原因。这里的细节,但被警告:你可能会斗鸡眼
的http://$c$c.google.com/apis/analytics/docs/gdata/gdataReferenceValidCombos.html
哦,使用.NET库中,您不需要连接code等于符号或空格,你的过滤器。我的结构我的过滤器是这样的:
私有静态只读字符串过滤器=的string.join
(
;,新的String []
{
嘎!城市=西米谷,// URL编码为您处理
嘎!pagePath @ /扑通一声,
嘎!pagePath @static_test
嘎!networkLocation @spring
嘎!networkLocation @equinix亚太私人有限公司
// ...
}
);
希望这可以帮助别人!
Good afternoon! I've been searching StackOverflow and the web for about 24 hours now, and I haven't found an answer yet. I hope I'm missing something simple that a more experienced API user can point out for me.
I'm querying the Google Analytics API using their .NET library. This request works:
https://www.google.com/analytics/feeds/data?start-index=1&max-results=500&dimensions=ga:date&end-date=2011-01-06&ids=ga:________&metrics=ga:visitors,ga:visits&start-date=2011-01-06
...but I'd like to filter the results. I've tried a single very simple filter which does not require URL encoding:
filters=ga:city!@Minsk
All I get is the maddeningly vague "400 bad request" error. I get the same result using the equals operator:
DataQuery query = new DataQuery(URL);
...
query.Filters = "ga:city==Minsk"
Ditto if I encode the equals signs as %3D. This gets translated into "ga:city%253D%253DMinsk", according to the error message. I've tried single-quoting "Minsk", and double-quoting it; no luck.
I'm stumped. Any ideas? Thanks!
Found it. It turns out that filters have to be "compatible" with the dimensions and metrics actually expressed in a query. Dropping ga:visitors allowed me to apply most of the filters I needed, though the combination of ga:pagePath and ga:campaign is not allowed with ga:visits... for some reason. Here's the detail, but be warned: you may end up cross-eyed.
http://code.google.com/apis/analytics/docs/gdata/gdataReferenceValidCombos.html
Oh, and using the .NET library you do not need to encode equals signs or spaces in your filters. I structured my filters like this:
private static readonly string Filter = string.Join
(
";", new string[]
{
"ga:city!=Simi Valley", // URL encoding is handled for you
"ga:pagePath!@/splash",
"ga:pagePath!@static_test",
"ga:networkLocation!@spring",
"ga:networkLocation!@equinix asia pacific pte ltd"
// ...
}
);
Hope this helps someone!
这篇关于谷歌Analytics(分析)API - 通过.NET过滤 - 因此关闭!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!