Skip to content

Instantly share code, notes, and snippets.

@cameronwlewis
Forked from codeas/gas-google-nlp.js
Created July 20, 2019 11:15
Show Gist options
  • Save cameronwlewis/f1dfebecdc82f0d923c772e03afa6a94 to your computer and use it in GitHub Desktop.
Save cameronwlewis/f1dfebecdc82f0d923c772e03afa6a94 to your computer and use it in GitHub Desktop.
GAS Google NLP
/*
* Get sentiment from Google Cloud Natural Language API
*/
var getSentiment = function(text) {
var apiKey = PropertiesService.getScriptProperties().getProperty("apiKey")
var url = "https://language.googleapis.com/v1/documents:analyzeSentiment?key=%KEY".replace("%KEY", apiKey)
var data = {
document: {
language: "en-us",
type: "PLAIN_TEXT",
content: text
},
encodingType: 'UTF8'
};
var parameters = {
method : 'post',
contentType: 'application/json',
payload : JSON.stringify(data)
};
var response = UrlFetchApp.fetch(url, parameters);
return (response);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment