我試圖爲第4版API 發送請求我做這個簡單的要求谷歌分析報告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."
}
]
}
]
我做錯了什麼?
您使用的是什麼內容類型? – DaImTo
content-type:application/json; charset = UTF-8 –
沒有使用 內容類型:application/x-www-form-urlencoded; charset = UTF-8 –