感情分析できるプログラムをつくりたい
解決したいこと
GASで感情分析を行いたいのですがエラーが表示されてしまいます。
API KEY が間違っているのでしょうか??
APIの取得方法は以下のものを参考にしました。
https://dev.1dz.jp/spreadsheet-natural-language-api/
発生している問題・エラー
エラー
Exception: Request failed for https://language.googleapis.com returned code 400. Truncated server response: {
"error": {
"code": 400,
"message": "API key not valid. Please pass a valid API key.",
"status": "INVALID_ARGUMENT",
"details": ... (use muteHttpExceptions option to examine full response)
analyzeSentiment @ コード.gs:26
myFunction @ コード.gs:28
該当するソースコード
function myFunction() {
/*---------------------------
GASで感情分析API叩く
--------------------------*/
var API_KEY = PropertiesService.getScriptProperties().getProperty("********");
//***分析する文章を書く***
var content = "友情は多くは見せかけであり、恋は多くの愚かさにすぎない。"
//レスポンスはJSONで返る
function analyzeSentiment(content){
var data = {
'document' : {
'type' : 'PLAIN_TEXT',
'language' : 'ja',
'content' : content
},
'encodingType': 'UTF8'
};
var params = {
'contentType' : 'application/json',
'method' : 'post',
'payload' : JSON.stringify(data)
};
var url = 'https://language.googleapis.com/v1/documents:analyzeSentiment?key='+ API_KEY;
return UrlFetchApp.fetch(url, params);
}
Logger.log(JSON.parse(analyzeSentiment(content))["documentSentiment"]["score"])
}
0 likes