Skip to content

Instantly share code, notes, and snippets.

@toast38coza
Last active November 11, 2016 12:20
Show Gist options
  • Save toast38coza/8c3d13f0378aa8f6360530615cd8a938 to your computer and use it in GitHub Desktop.
Save toast38coza/8c3d13f0378aa8f6360530615cd8a938 to your computer and use it in GitHub Desktop.
Using the Google natural language API with python
# 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
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