Skip to content

Instantly share code, notes, and snippets.

@cosu
Created December 4, 2016 10:01
Show Gist options
  • Save cosu/848a543b7d447cfacdf2fb6b0c05b416 to your computer and use it in GitHub Desktop.
Save cosu/848a543b7d447cfacdf2fb6b0c05b416 to your computer and use it in GitHub Desktop.
microsoft translator api
import requests
def auth(subscription_key):
url = 'https://api.cognitive.microsoft.com/sts/v1.0/issueToken?Subscription-Key=' + subscription_key
response = requests.post(url)
return response.text
def translate(text, token, from_language, to_language):
url = 'https://api.cognitive.microsoft.com/sts/v1.0'
headers = {
'Authorization': 'Bearer ' + token
}
params = {
'from': from_language,
'to': to_language,
'text': text
}
response = requests.get(headers=headers, url=url, params=params)
return response
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment