Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@Sam0711er Sam0711er commented Jun 5, 2019

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