【发布时间】:2015-05-04 16:52:10
【问题描述】:
下面我有来自谷歌分析 API 的结果。这是我从developers.google.com 运行的查询的输出。
"start-date": "2015-04-01",
"end-date": "today",
"dimensions": "ga:source",
"metrics": [
"ga:users"
],
"sort": [
"-ga:users"
],
{
"name": "ga:source",
"columnType": "DIMENSION",
"dataType": "STRING"
},
{
"name": "ga:users",
"columnType": "METRIC",
"dataType": "INTEGER"
}
],
"totalsForAllResults": {
"ga:users": "2201795"
},
"rows": [
[
"(direct)",
"869648"
],
[
"sa",
"591843"
],
我试图在我的代码(ruby)中做的是从“行”中提取信息。我需要推荐名称“sa”和用户数“591843”。
这是我试图做到这一点的方式。
sa_referral = client.execute(:api_method => analytics.data.ga.get, :parameters => {
'ids' => "ga:" + saprofileID,
'dimensions' => "ga:fullreferrer",
'metrics' => "ga:users",
'sort' => "-ga:users",
'filters' => "ga:ga:source!=us-mg6.mail.yahoo.com;ga:source!=sa;ga:source!=(direct);ga:source!=mail.google.com;ga:source!=us-mg5.mail.yahoo.com;ga:source!=SA;ga:source!=m.mg.mail.yahoo.com;ga:source!=mail.aol.com;ga:source!=us-mg4.mail.yahoo.com;ga:source!=yahoo;ga:source!=bing;ga:source!=google;ga:source!=weibo;ga:fullreferrer!=eccie.net/showthread.php",
'start-date' => startDate,
'end-date' => endDate,
})
sa_referral_data = sa_referral.rows do |row|
rows.map{|r| { referrals:r[0], members:r[1] }}
end
puts sa_referral_data
puts sa_referral_data 的结果如下
scheduler caught exception:
undefined method `rows' for #<Google::APIClient::Result:0x000000044651f0>
API 似乎根本没有从行中获取信息。有没有办法可以对 API 进行故障排除,看看为什么它会丢失“行”部分的数据?
【问题讨论】:
标签: ruby google-analytics