以下是获取GA数据的API v4页面
https://developers.google.com/analytics/devguides/reporting/core/v4/rest/v4/reports/batchGet
我的要求:
{
"reportRequests": [
{
"dateRanges": [
{
"startDate": "7daysAgo",
"endDate": "yesterday"
}
],
"metrics": [
{
"expression": "ga:users"
}
]
},
{
"viewId": "ga:123456"
}
]
}
回复:
{
"error": {
"code": 400,
"message": "Parameter viewId must be set.",
"status": "INVALID_ARGUMENT"
}
}
Query Explorer使用相同的ViewID和request参数,它正在正确获取数据。我缺少什么?
答案 0 :(得分:1)
您错过了第一个viewId
对象中的ReportRequest
密钥。将viewId
独立放在单独的对象中并不起作用。请尝试使用此代码:
{
"reportRequests": [
{
"viewId": "ga:123456", //viewId defined within the ReportRequest object itself
"dateRanges": [
{
"startDate": "7daysAgo",
"endDate": "yesterday"
}
],
"metrics": [
{
"expression": "ga:users"
}
]
}
]
}
答案 1 :(得分:0)
您缺少像ga:date这样的维度。以下是可在GA-API中使用的维度的列表:https://developers.google.com/analytics/devguides/reporting/core/dimsmets