Created
December 4, 2016 10:01
-
-
Save cosu/848a543b7d447cfacdf2fb6b0c05b416 to your computer and use it in GitHub Desktop.
microsoft translator api
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 | |
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