GMB API 见解无效 JSON 已收到有效载荷
GMB API Insights Invalid JSON Payload received
我正在尝试使用 Google Apps 脚本和 Google 我的业务 Api。
来深入了解我们的位置
获得评论和其他东西没什么大不了的。
代码在 OAuth2 Playground 中运行良好。
请求如下:
var myBusinessService = getMyBusinessService();
var payload ={
"locationNames":["accounts/116447162401331885225/locations/10722475831894877870"],
"basicRequest": {
"metricRequests": [{
"metric": "ALL"
}],
"timeRange": {
"startTime": "2017-01-01T00:00:01.045123456Z",
"endTime": "2017-01-31T23:59:59.045123476Z"
}
}
};
var options = {
"headers":{
"Authorization": 'Bearer ' + myBusinessService.getAccessToken()
},
"method": "POST",
"payload": payload,
"muteHttpExceptions": true
};
var response = UrlFetchApp.fetch('https://mybusiness.googleapis.com/v4/accounts/116447162401331885225/locations:reportInsights', options);
回复:
{error={code=400, details=[Ljava.lang.Object;@3116fd89, message=Invalid JSON payload received. Unknown name "basicRequest": Cannot bind query parameter. 'basicRequest' is a message type. Parameters can only be bound to primitive types., status=INVALID_ARGUMENT}}
希望有人能帮我解决这个问题。
此致
蒂斯
您将 payload
作为 JavaScript 对象发送。根据错误消息 ("message=Invalid JSON payload received."),您需要将其作为 JSON 发送。使用 JSON.stringify()
使 payload
成为 JSON 字符串。
var options = {
"headers":{
"Authorization": 'Bearer ' + myBusinessService.getAccessToken()
},
"method": "POST",
"payload": JSON.stringify(payload),
"muteHttpExceptions": true
};
我正在尝试使用 Google Apps 脚本和 Google 我的业务 Api。
来深入了解我们的位置获得评论和其他东西没什么大不了的。
代码在 OAuth2 Playground 中运行良好。
请求如下:
var myBusinessService = getMyBusinessService();
var payload ={
"locationNames":["accounts/116447162401331885225/locations/10722475831894877870"],
"basicRequest": {
"metricRequests": [{
"metric": "ALL"
}],
"timeRange": {
"startTime": "2017-01-01T00:00:01.045123456Z",
"endTime": "2017-01-31T23:59:59.045123476Z"
}
}
};
var options = {
"headers":{
"Authorization": 'Bearer ' + myBusinessService.getAccessToken()
},
"method": "POST",
"payload": payload,
"muteHttpExceptions": true
};
var response = UrlFetchApp.fetch('https://mybusiness.googleapis.com/v4/accounts/116447162401331885225/locations:reportInsights', options);
回复:
{error={code=400, details=[Ljava.lang.Object;@3116fd89, message=Invalid JSON payload received. Unknown name "basicRequest": Cannot bind query parameter. 'basicRequest' is a message type. Parameters can only be bound to primitive types., status=INVALID_ARGUMENT}}
希望有人能帮我解决这个问题。
此致
蒂斯
您将 payload
作为 JavaScript 对象发送。根据错误消息 ("message=Invalid JSON payload received."),您需要将其作为 JSON 发送。使用 JSON.stringify()
使 payload
成为 JSON 字符串。
var options = {
"headers":{
"Authorization": 'Bearer ' + myBusinessService.getAccessToken()
},
"method": "POST",
"payload": JSON.stringify(payload),
"muteHttpExceptions": true
};