I am currently developing GA reporting web app for my company using asp.net Google api V3(Google.Apis.Analytics.v3.dll). I understand there is older version of .net api and some example for it but when there is newer version I might as well use it. This following code snippet is how you send query to retrieve GA data using Google.GData.Analytics.dll. But it's older version.
我目前正在为我的公司开发一个使用asp.net谷歌api V3(Google. api . analytics.v3 .dll)的GA报表web应用程序。我知道有。net api的旧版本和一些例子,但如果有更新的版本,我也可以使用它。下面的代码片段是如何使用Google.GData.Analytics.dll发送查询以检索GA数据的。但它是旧版本。
AnalyticsService _service = new AnalyticsService("GoogleAnalytics");
_service.setUserCredentials("YourUsername", "YourPassword");
DataQuery dataQuery = new DataQuery(Conststr_Url);
dataQuery.Ids = "ga:xxxxxx";
dataQuery.Dimensions = "ga:date";
dataQuery.Metrics = "ga:visits";
dataQuery.GAStartDate = "2012-05-10";
dataQuery.GAEndDate = "2012-05-24";
DataFeed visits = _service.Query(dataQuery);
foreach (DataEntry entry in visits.Entries)
{
Response.Write("Date: " + entry.Title.Text.Replace("ga:date=", "") + " Visits: " + entry.Metrics[0].Value + "<br />");
}
With version3, I managed to do oauth2 authorisation part successfully using Tasks.ASP.NET.SimpleOAuth2 sample application they provide. But when I try to replace the task service with google analytic service, I just don't know where to start. All I know is declaring the analytic service, and from that point I have nothing to go on :) .Can anyone help me with abit of code snippets or direct me to an exmaple site.
使用version3,我成功地使用task . asp.net完成了oauth2授权部分。他们提供的SimpleOAuth2示例应用程序。但是当我尝试用谷歌分析服务替换任务服务时,我不知道从哪里开始。我所知道的只是声明分析服务,从那时起我就没有什么可说的了。)谁能帮助我编写代码片段的abit,或者指导我到一个exmaple站点。
Thank you very much in advance.
非常感谢。
1 个解决方案
#1
3
After searching around on * and google for a few days, here is what I found out. Unlike previous version, you need to create a "GetRequest" object using AnalyticService and fetch the data using that object to get "GaData" result object back. Here is the code:
在*和谷歌上搜索了几天之后,我发现了以下内容。与以前的版本不同,您需要使用AnalyticService创建一个“GetRequest”对象,并使用该对象获取数据以获取“GaData”结果对象。这是代码:
var request = _analyticsService.Data.Ga.Get(ProfileID, StartDate, EndDate, Metrics);
request.Dimensions = Dimensions;
request.Segment = Segment;
request.Sort = Sort;
request.StartIndex = StartIndex;
request.MaxResults = MaxResult;
GaData results = request.Fetch();
#1
3
After searching around on * and google for a few days, here is what I found out. Unlike previous version, you need to create a "GetRequest" object using AnalyticService and fetch the data using that object to get "GaData" result object back. Here is the code:
在*和谷歌上搜索了几天之后,我发现了以下内容。与以前的版本不同,您需要使用AnalyticService创建一个“GetRequest”对象,并使用该对象获取数据以获取“GaData”结果对象。这是代码:
var request = _analyticsService.Data.Ga.Get(ProfileID, StartDate, EndDate, Metrics);
request.Dimensions = Dimensions;
request.Segment = Segment;
request.Sort = Sort;
request.StartIndex = StartIndex;
request.MaxResults = MaxResult;
GaData results = request.Fetch();