Skip to content

Instantly share code, notes, and snippets.

@codeas
Created March 6, 2018 21:51
Show Gist options
  • Save codeas/3a5feae448ed59cc0f9cbdb8f2e0853e to your computer and use it in GitHub Desktop.
Save codeas/3a5feae448ed59cc0f9cbdb8f2e0853e 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