2017-10-16 5 views
0
나는 항상 오류 (400), 내 아약스 호출은 다음과 같습니다 반환 https://language.googleapis.com/v1/documents:analyzeEntitySentiment에 아약스 호출을 전송, 실체 심리를 감지하는 자연 언어를 구글 사용하고

,Google 자연어 REST API가 오류 400을 반환합니다. 잘못된 JSON 페이로드가 수신되었습니다. 알 수없는 이름 "문서 ": "

{

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); 
     } 
    }); 

오류 :

"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." 
     } 
    ] 
    } 
] 

다큐에서 언급 https://cloud.google.com/natural-language/docs/reference/rest/v1/documents/analyzeEntitySentiment "문서"는 요청 본문 데이터로 사용해야합니다.

미리 감사드립니다.

답변

1

문서에서 JSON.Stringify 호출을 제거하십시오. 페이로드는 이미 문자열 형식입니다.

data  : { 
        "document": { "type":"PLAIN_TEXT", 
             "content":"Nature is so beautiful" 
            }, 
        "encodingType":"UTF8" 
       }, 
관련 문제