-
-
Save cameronwlewis/f1dfebecdc82f0d923c772e03afa6a94 to your computer and use it in GitHub Desktop.
GAS Google NLP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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