【发布时间】:2016-10-24 06:16:22
【问题描述】:
我正在尝试发送版本 4 api 的请求 我正在做这个简单的请求
$.ajax({
url: 'https://analyticsreporting.googleapis.com/v4/reports:batchGet',
headers: {
"Authorization":"Bearer xxxx"
},
method:"POST",
data:{
"reportRequests":[
{
"viewId":"xxx",
"dateRanges":[
{
"startDate":"2015-06-15",
"endDate":"2015-06-30"
}],
"metrics":[
{
"expression":"ga:sessions"
}],
"dimensions": [
{
"name":"ga:browser"
}]
}]
},
success: function(resp){
alert(resp);
}
});
但是返回错误。
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"reportRequests[0][metrics][0][expression]\": Cannot bind query parameter. Field 'reportRequests[0][metrics][0][expression]' could not be found in request message."
},
{
"description": "Invalid JSON payload received. Unknown name \"reportRequests[0][dateRanges][0][endDate]\": Cannot bind query parameter. Field 'reportRequests[0][dateRanges][0][endDate]' could not be found in request message."
},
{
"description": "Invalid JSON payload received. Unknown name \"reportRequests[0][dimensions][0][name]\": Cannot bind query parameter. Field 'reportRequests[0][dimensions][0][name]' could not be found in request message."
},
{
"description": "Invalid JSON payload received. Unknown name \"reportRequests[0][dateRanges][0][startDate]\": Cannot bind query parameter. Field 'reportRequests[0][dateRanges][0][startDate]' could not be found in request message."
},
{
"description": "Invalid JSON payload received. Unknown name \"reportRequests[0][viewId]\": Cannot bind query parameter. Field 'reportRequests[0][viewId]' could not be found in request message."
}
]
}
]
我做错了什么?
【问题讨论】:
-
您使用的是什么内容类型?
-
内容类型:应用程序/json; charset=UTF-8
-
我不使用 Content-Type:application/x-www-form-urlencoded; charset=UTF-8
标签: ajax google-api google-analytics-api