Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用.NET从Google Analytics API检索数据,多指标?_C#_.net_Google Analytics_Google Analytics Api_Google Api Client - Fatal编程技术网

C# 使用.NET从Google Analytics API检索数据,多指标?

C# 使用.NET从Google Analytics API检索数据,多指标?,c#,.net,google-analytics,google-analytics-api,google-api-client,C#,.net,Google Analytics,Google Analytics Api,Google Api Client,我正在编写这个控制台应用程序,以获得一些基本的“谷歌分析Api数据”逻辑。一切正常,但我不想在google analytics API中添加更多的查询指标。我不想添加ga:newvisitors、ga:reaccuringvisitors等。我如何在下面的代码中实现这一点 下面是一段相关的代码: var gas = new AnalyticsService(new BaseClientService.Initializer() { HttpClientInitializ

我正在编写这个控制台应用程序,以获得一些基本的“谷歌分析Api数据”逻辑。一切正常,但我不想在google analytics API中添加更多的查询指标。我不想添加ga:newvisitors、ga:reaccuringvisitors等。我如何在下面的代码中实现这一点

下面是一段相关的代码:

var gas = new AnalyticsService(new BaseClientService.Initializer()
      {
       HttpClientInitializer = credential,
       ApplicationName = "TestGoogleAnalytics",
       });

var r = gas.Data.Ga.Get("ga:ProfileID", "2010-02-24", "2014-02-24", "ga:visitors");

//Specify some addition query parameters
r.Dimensions = "ga:pagePath";
r.Sort = "-ga:visitors";
r.MaxResults = 10000;

//Execute and fetch the results of our query
Google.Apis.Analytics.v3.Data.GaData d = r.Execute();
foreach (KeyValuePair<string, string> kvp in d.TotalsForAllResults)
    {
    Console.WriteLine("Total Visitors:" +" " + kvp.Value);
    }

Console.WriteLine(d.TotalsForAllResults.Keys + " = " + d.TotalsForAllResults.Values);
Console.ReadLine();
var gas=新的分析服务(新的BaseClientService.Initializer()
{
HttpClientInitializer=凭证,
ApplicationName=“TestGoogleAnalytics”,
});
var r=gas.Data.Ga.Get(“Ga:ProfileID”、“2010-02-24”、“2014-02-24”、“Ga:visitors”);
//指定一些附加查询参数
r、 Dimensions=“ga:pagePath”;
r、 Sort=“-ga:访客”;
r、 MaxResults=10000;
//执行并获取查询结果
Google.api.Analytics.v3.Data.GaData d=r.Execute();
foreach(d.TotalsForAllResults中的KeyValuePair kvp)
{
Console.WriteLine(“总访客数:”+“”+kvp.Value);
}
Console.WriteLine(d.TotalsForAllResults.Keys+“=”+d.TotalsForAllResults.Values);
Console.ReadLine();

谢谢,度量是get请求中的最后一项,请用逗号分隔

var r = gas.Data.Ga.Get("ga:ProfileID", "2010-02-24", "2014-02-24", "ga:visitors,ga:newvisitors,ga:reaccuringvisitors");
这样读可能更容易:

string Metrics = "ga:visitors,ga:newvisitors,ga:reaccuringvisitors";
var r = gas.Data.Ga.Get("ga:ProfileID", "2010-02-24", "2014-02-24", Metrics);
确保你的名字是正确的那些我看不正确,但我没有检查:


更新:早在2009年就被删除了。我找不到任何关于ga:reaccuringvisitors的参考资料。确保您请求的指标正确。

嗯,好吧,我做了类似的事情,但我猜代码的格式是错误的。谢谢,我会试试这个=)哦,我不知道他们把它拿走了,我需要更多的统计数据来绘制图表。Reacurringvisitors并不令人兴奋,但我认为ga:PercentNewVisitions可以使用。然而,当我运行代码时会出现这个错误,当我像这样执行“r”时就会出现错误,比如Google.api.Analytics.v3.Data.GaData d=r.execute();错误显示“ids”ga的参数验证失败ga:ProfileID是ga中您要访问的配置文件的Id。请转到视图的管理员查看它的“视图设置”下的“视图Id”它的编号您必须将ga:放在它的前面(ga:78110423)它现在可以工作了谢谢!我在使用“字符串度量”时遇到了Id问题“但您提供的另一种替代方案有效。我现在得到总访客和百分比newvisions=)