Skip to content

Instantly share code, notes, and snippets.

@cobookman
Last active May 12, 2017 15:50
Show Gist options
  • Save cobookman/b8dcf407b9db76a04a25b1452cf46c7f to your computer and use it in GitHub Desktop.
Save cobookman/b8dcf407b9db76a04a25b1452cf46c7f to your computer and use it in GitHub Desktop.
Translate API Examples

How to get an API Key.

  1. Head to API Manager
  2. Click on credentials
  3. Create new credential->Api Key
  4. Your api key is a string in the form of something like: BIzqTyzdDdg3fBqaouJI6z2nC3ygJNZ1qZsoYGc
"""Example translate API Call."""
import requests
API_KEY="...." # Your API Key
API_URL="https://translation.googleapis.com/language/translate/v2"
r = requests.post(API_URL, data={
"key": API_KEY,
"q": "Hi World",
"target": "de",
})
print(r.text)
#!/bin/bash
API_KEY="....." # Your API Key
DATA="{
'q': 'Hello world',
'target': 'de'
}"
curl -XPOST \
-H "Content-Type: application/json" \
--data "$DATA" \
"https://translation.googleapis.com/language/translate/v2?key=${API_KEY}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment