[英]Google Natural language REST API returns error 400 Invalid JSON payload received. Unknown name \“document\”: "
I am using google natural language to detect entity sentiment, sending ajax call to https://language.googleapis.com/v1/documents:analyzeEntitySentiment always returns error 400, my ajax call is as below, 我正在使用Google自然语言检测实体情感,将ajax调用发送到https://language.googleapis.com/v1/documents:analyzeEntitySentiment始终返回错误400,我的ajax调用如下所示,
{ {
APIKEY = '**********************'; APIKEY ='**********************';
$.ajax({
type : "POST",
url : "https://language.googleapis.com/v1/documents:analyzeEntitySentiment?key="+APIKEY,
ContentType : "application/json",
data : {
"document": JSON.stringify(
{ "type":"PLAIN_TEXT",
"content":"Nature is so beautiful"
}),
"encodingType":"UTF8"
},
success : function(_result){
if (_result) {
alert('SUCCESS');
}else{
alert('ERROR');
}
},
error : function(_result){
alert(_result);
}
});
and error : 和错误:
"code": 400,
"message": "Invalid JSON payload received. Unknown name \"document\": Cannot bind query parameter. 'document' is a message type. Parameters can only be bound to primitive types.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"description": "Invalid JSON payload received. Unknown name \"document\": Cannot bind query parameter. 'document' is a message type. Parameters can only be bound to primitive types."
}
]
}
]
as mentioned in document https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeEntitySentiment "document" should be used as request body data. 如文件https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeEntitySentiment “文档”中所述,“文档”应用作请求正文数据。
Thanks in advance! 提前致谢!
Remove the JSON.Stringify call on the document. 删除文档上的JSON.Stringify调用。 Your payload is already in string format. 您的有效载荷已经是字符串格式。
data : {
"document": { "type":"PLAIN_TEXT",
"content":"Nature is so beautiful"
},
"encodingType":"UTF8"
},
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.