Last active
November 11, 2016 12:20
-
-
Save toast38coza/8c3d13f0378aa8f6360530615cd8a938 to your computer and use it in GitHub Desktop.
Using the Google natural language API with python
This file contains hidden or 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
| # install gcoud SDK https://cloud.google.com/sdk/downloads | |
| gcloud auth activate-service-account --key-file=/path/to/project/application-key.json | |
| gcloud auth print-access-token |
This file contains hidden or 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
| import requests, json | |
| token = "..." | |
| url = "https://language.googleapis.com/v1beta1/documents:analyzeEntities" | |
| data = { | |
| "document":{ | |
| "type": "PLAIN_TEXT", | |
| "content": "Michelangelo Caravaggio, Italian painter, is known for 'The Calling of Saint Matthew'." | |
| }, | |
| "encodingType": "UTF8" | |
| } | |
| headers = { | |
| "Authorization": "Bearer {}" . format(token), | |
| "content-type": "application/json" | |
| } | |
| requests.post(url, data=json(data), headers=headers) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment