-
Notifications
You must be signed in to change notification settings - Fork 15
/
queryAPITextRazor.gs
41 lines (36 loc) · 1.28 KB
/
queryAPITextRazor.gs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
function getTopicsFromTextRazor() {
var ss = SpreadsheetApp.getActiveSpreadsheet();
var sheet = ss.getSheetByName([YOUR SHEET]);
var lastRow = sheet.getLastRow();
var lastColumn = sheet.getLastColumn();
var range = sheet.getRange(1,1,lastRow,lastColumn);
var url = 'https://api.textrazor.com';
for (i = 2; i <= lastRow; i++){
var payload = {"extractors":"entities,topics",
"text":'"' + range.getCell(i, 7).getValue() + '"'}; //for entitties and topics
var options =
{
'method' : 'POST',
'followRedirects' : true,
'muteHttpExceptions': true,
"headers": {
"Content-Type": "application/json",
"X-TextRazor-Key": "[YOUR API KEY]"
},
'payload': payload
};
var response = UrlFetchApp.fetch(url, options);
var json = response.getContentText();
var data = JSON.parse(json);
//keyword
var keywordplus = "";
for(var a = 0;(data.response.topics) && (data.response.topics[a].score>=0.5); a++){
keywordplus = keywordplus + data.response.topics[a].label;
if (data.response.topics[a+1].score<0.5){
break;
}
keywordplus = keywordplus + ",";
}
range.getCell(i, 8).setValue(keywordplus);
}
}