2009-06-17 39 views
0

我正嘗試使用Google Analytics數據API獲取按國家/地區過濾的數據。我使用.NET庫http://google-gdata.googlecode.com/svn/trunk/,只要我不嘗試按國家進行過濾,它的效果非常好。使用谷歌分析數據API按國家過濾

這工作得很好:

const string dataFeedUrl = "https://www.google.com/analytics/feeds/data"; 

var query = new DataQuery(dataFeedUrl); 
query.Ids = this.ProfileID; 
query.GAStartDate = this.FromDate; 
query.GAEndDate = this.ToDate; 
query.Metrics = "ga:newVisits,ga:visitors"; 

DataFeed dataFeed = this.AnalyticsService.Query(query); 

但是,如果我查詢調用之前補充一點:

query.Filters = string.Format("ga:country=={0}", this.Country); 
query.Dimensions = "ga:country"; 

...我得到這個異常:

System.Exception {Google.GData.Client.GDataRequestException} 
"Execution of request failed: https://www.google.com/analytics/feeds/data?dimensions=ga:country&end-date=2009-06-17&filters=ga:country==Denmark&ids=ga:xxx&metrics=ga:newVisits,ga:visitors&start-date=2009-05-18" 

我已經嘗試手動轉義==到%3D%3D,但沒有幫助。

任何想法?

+0

當您將==編碼爲%3D%3D時出現什麼錯誤? (對我來說,這是這裏唯一的問題) – 2009-06-17 17:44:32

回答

0

我終於找到了ResponseString,看到這條消息:

"Illegal combination of dimensions and metrics" 

顯然,我一直在試圖讓不可用的數據。這在查看文檔中的Query Validation Chart時確實有意義。