2012-09-26 87 views
0

我能够从谷歌分析获取数据api.How我得到这样的国家明智的页面数据visit.I尝试的组合:操纵谷歌分析数据

var query1 = asv.Data.Ga.Get("ga:xxxxxxxx", startDate, endDate, "ga:pageviews,ga:country"); 
    query1.Metrics = "ga:country";//Gives error(can not be assigned to -- it is read only.) 
    query1.Dimensions = "ga:country"; 
    query1.Sort = "ga:country,ga:pageviews"; 
    query1.StartIndex = 1; 
    var report1 = query1.Fetch(); 

我想在网格中获取记录和绑定。我的错误在哪里。如果我评论该行
query1.Fetch();给出错误意味着无法获得记录。 当我使用

var request = asv.Data.Ga.Get("ga:xxxxxxxx", startDate, endDate, "ga:visits,ga:pageviews,ga:bounces");

其顺利拿到record.Thanks。

回答

0

我得到一个解决方案,所以我张贴它以备将来参考。

var query1 = asv.Data.Ga.Get("ga:63104444", startDate, endDate, "ga:visits"); 

    query1.Dimensions = "ga:country"; 
    query1.Sort = "-ga:visits"; 

    var report1 = query1.Fetch(); 

    List<KeyValuePair<string, object>> CountryWiseVisitList = new List<KeyValuePair<string, object>>(); 
    foreach (IList<string> lstRow in report1.Rows) 
    { 
    CountryWiseVisitList.Add(new KeyValuePair<string, object>(lstRow[0].ToString(), lstRow[1].ToString()));    
    } 
    gdvCountryWiseVisit.DataSource = CountryWiseVisitList; //Bind on grid 
    gdvCountryWiseVisit.DataBind();