0

シンプルな API キーだけで Google の Natural Language Cloud API を使用できますか? 認証ドキュメントは、cURL テストに使用することを提案しているようですが、以下のコードを試してみると、URL で 404 メッセージが表示されます。

<html>
  <head>
    <script src="https://apis.google.com/js/api.js"></script>
    <script>
      function start() {
        gapi.client.init({
          'apiKey': 'XXXXXXX'
        }).then(function() {
          return gapi.client.request({
            path: '/v1beta1/documents:analyzeSentiment',
            method: 'POST',
            body: {'document': {
                      'type': 'PLAIN_TEXT',
                      'content': 'ANALZE THIS, IS IT BAD?'
                   } 
            }  
          });
        }).then(function(resp) {
          console.log(resp.result);
        }, function(reason) {
          console.log('Error: ' + reason.result.error.message);
        });
      };
      gapi.load('client', start);
    </script>
  </head>
  <body>
    <div id="results"></div>
  </body>
</html>
4

1 に答える 1