?text=колено&lang=1049
https://developers.lingvolive.com/api/v1/WordForms?text=колено&lang=1049
- не работает //Подготовка заголовков к авторизации
$header = array();
$header[] = 'Content-length: 0';
$header[] = 'Content-type: application/json';
$header[] = 'Authorization: Basic {Ваш ключ для доступа к API}';
//Авторизация в ABBYY Lingvo API посредством отправки ключа авторизации
$myCurl = curl_init();
curl_setopt_array($myCurl, array(
CURLOPT_URL => 'https://developers.lingvolive.com/api/v1.1/authenticate',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_HTTPHEADER => $header
));
$bearer_token = curl_exec($myCurl);
curl_close($myCurl);
//Модификация заголовков для получения данных
$header[2] = 'Authorization: Bearer '.$bearer_token;
//Получение словарной статьи
$myCurl = curl_init();
curl_setopt_array($myCurl, array(
CURLOPT_URL => 'https://developers.lingvolive.com/api/v1/Minicard?text=plum&srcLang=1033&dstLang=1049',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => $header
));
$response = curl_exec($myCurl);
curl_close($myCurl);
//Тут я просто вывожу ответ сервера чтобы убедиться, что всё работает.
echo '<pre>';
print_r(json_decode($response));
echo '</pre>';
import requests
import json
URL_AUTH = 'https://developers.lingvolive.com/api/v1.1/authenticate'
URL_TRANSLATE = 'https://developers.lingvolive.com/api/v1/Minicard'
KEY = 'Ключ для доступа к API'
def get_a_word_translation(key: str) -> str:
headers_auth = {'Authorization': 'Basic ' + KEY}
auth = requests.post(URL_AUTH, headers=headers_auth)
if auth.status_code == 200:
token = auth.text
headers_translate = {
'Authorization': 'Bearer ' + token
}
params = {
'text': key,
'srcLang': 1033,
'dstLang': 1049
}
req = requests.get(
URL_TRANSLATE, headers=headers_translate, params=params)
res = req.json()
try:
value = res['Translation']['Translation']
return value
except TypeError:
if res == 'Incoming request rate exceeded for 50000 chars per day pricing tier':
return res
else:
return None
else:
print('Error!' + str(auth.status_code))
if __name__ == "__main__":
not_translated_words_test = ['victim', 'home', 'root']
translated_words_test = {}
for en in not_translated_words_test:
ru = get_a_word_translation(en)
if ru == 'Incoming request rate exceeded for 50000 chars per day pricing tier':
break
translated_words_test[en] = ru
save_data_to_json('data/translated_words_test.json',
translated_words_test)
URL_AUTH = 'https://developers.lingvolive.com/api/v1.1/authenticate'
URL_TRANSLATE = 'https://developers.lingvolive.com/api/v1/Minicard'
KEY = 'Ключ для доступа к API'
def get_auth_token(key: str, url_auth: str) -> str:
headers_auth = {'Authorization': 'Basic ' + key}
auth = requests.post(url=url_auth, headers=headers_auth)
if auth.status_code == 200:
cur_token = auth.text
return cur_token
else:
print('Error - ' + str(auth.status_code))
return ''
def get_a_word_translation(cur_token: str, url_tr: str, word: str) -> str:
headers_translate = {
'Authorization': 'Bearer ' + cur_token
}
params = {
'text': word,
'srcLang': 1033,
'dstLang': 1049
}
req = requests.get(
url_tr, headers=headers_translate, params=params)
if req.status_code == 200:
res = req.json()
try:
value = res['Translation']['Translation']
return value
except TypeError:
if res == 'Incoming request rate exceeded for 50000 chars per day pricing tier':
print('Error - Incoming request rate exceeded for 50000 chars per day pricing tier')
return res
else:
return 'No translation available'
else:
print('Error!' + str(req.status_code))
if __name__ == "__main__":
token = get_auth_token(key=KEY, url_auth=URL_AUTH)
not_translated_words_test = ['victim', 'home', 'root']
for en_word in not_translated_words_test:
ru_translation = get_a_word_translation(cur_token=token, url_tr=URL_TRANSLATE, word=en_word)
if ru_translation == 'Incoming request rate exceeded for 50000 chars per day pricing tier':
break
print(ru_translation)