简体   繁体   English

Google自然语言REST API返回错误400接收到无效的JSON有效负载。 未知名称\\“ document \\”:“

[英]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.

相关问题 无效的 JSON 有效负载从 JavaScript/Ajax 接收到 Google 表格的写入 - Invalid JSON Payload Received writing to Google Sheet from JavaScript/Ajax 将JSON值传递给Web方法会返回“未知的Web方法DoesUserExist”。 参数名称:methodName'错误 - Passing JSON value to Web Method returns 'Unknown web method DoesUserExist. Parameter name: methodName' error Salesforce LiveAgent Rest API 400错误的请求错误 - Salesforce LiveAgent Rest API 400 Bad Request Error Firebase REST API POST请求失败,并显示错误:“数据无效; 无法解析JSON对象,数组或值...“ - Firebase REST API POST request fails with error: “Invalid data; couldn't parse JSON object, array, or value…” Ajax REST API Twitter授权问题:错误400错误请求 - Ajax REST API Twitter Authorization issue: error 400 Bad Request Firebase 动态链接 Rest API:未知名称“socialMetaTagInfo” - Firebase dynamic links Rest API: Unknown name "socialMetaTagInfo" AJAX 请求返回“实体不是格式正确的‘application/json’文档。 输入缺失或为空","code":"400"' - AJAX Request returns 'The entity is not a well-formed 'application/json' document. Missing or empty input","code":"400"' 使用 Rest 更新 SharePoint 列表中的文本字段返回错误代码 400 - Update of Text Field In SharePoint List Using Rest Returns An Error Code of 400 使用jQuery检索JSON API时发生无效错误 - Invalid Error when Retrieving JSON API with jQuery $ .ajax调用Google API时返回错误 - $.ajax returns error when calling google api
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM