Created
March 6, 2018 21:51
-
-
Save codeas/3a5feae448ed59cc0f9cbdb8f2e0853e 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