Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkEdmondson1234/ff857ef8c8e851d08c67bf057f4cc4e3 to your computer and use it in GitHub Desktop.
Save MarkEdmondson1234/ff857ef8c8e851d08c67bf057f4cc4e3 to your computer and use it in GitHub Desktop.
Authenticate to Google Natural Language API via client side javascript
<html>
<head>
<script src="https://apis.google.com/js/api.js"></script>
<script>
function start() {
gapi.client.init({
'apiKey': 'XXXX',
'discoveryDocs': ['https://language.googleapis.com/$discovery/rest?version=v1beta1']
}).then(function() {
return gapi.client.language.documents.analyzeSentiment({
'document': {
'type': 'PLAIN_TEXT',
'content': 'ANALZE THIS YOU MARVELLOUS SHIT'
}
});
}).then(function(resp) {
// send to dataLayer here
console.log(resp.result);
}, function(reason) {
console.log('Error: ' + reason.result.error.message);
});
};
gapi.load('client', start);
</script>
</head>
<body>
<h1>Natural Language API<h1>
Test page for authentication with https://cloud.google.com/natural-language/
</body>
</html>
@Sam0711er
Copy link

Thanks so much, this is gold for quick prototyping ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment