Last active
June 5, 2019 21:25
-
-
Save MarkEdmondson1234/ff857ef8c8e851d08c67bf057f4cc4e3 to your computer and use it in GitHub Desktop.
Authenticate to Google Natural Language API via client side javascript
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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks so much, this is gold for quick prototyping ❤️