GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEV
,
WEBDEV
e
WINDEV Mobile
Inicio
|
Mensagens recentes
|
Conecte-se...
|
Disconnect
|
Português
Inicio
→
WINDEV 2024
→
Using restRequest to access Microsoft Translate
Using restRequest to access Microsoft Translate
Iniciado por Simon Phillips, jul., 23 2021 1:42 PM - 2 respostas
Conecte-se…
Simon Phillips
#1
Publicado em julho, 23 2021 - 1:42 PM
Hi all
Has anyone managed to send a request to the Microsoft Translate service?
I have signed up for an Azure trial and have added the serial number to the request. However I have tried all the options but I either get a reply saying it is not authorized, or "The request is badly formed".
My code is:
cMyRequest is restRequest
cMyRequest.URL = "
https://api.cognitive.microsofttranslator.com/translate…
"" -H ""Ocp-Apim-Subscription-Key: <mysubscriptionkey>"" -H ""Content-Type: text/xml; charset=UTF-8"" -d ""[{'Text':'Hello, what is your name?'}]"
cMyReponse is httpResponse = RESTSend(cMyRequest)
IF ErrorOccurred THEN
Error(ErrorInfo(errFullDetails))
ELSE
Info(UTF8ToAnsi(cMyReponse.Content))
//This occurs, the it is getting there and a reply is being returned
END
Any help would be much apprecited.
Simon Phillips
OtterReg Software
Denunciar
0
0
Simon PHILLIPS
#2
Membro registado
32 mensagems
Popularité : +1 (1 vote)
Publicado em julho, 24 2021 - 12:45 PM
I've now moved onto Google Translate but still having problems. The API key works as I can set it up in the language options and it will successfully translate individual controls. However, when I put it in code the error I get back from google is:-
{ "error": { "code": 400, "message": "Missing required field target", "errors": [ { "message": "Missing required field target", "reason": "invalid" } ], "status": "INVALID_ARGUMENT" } }
The code is as follows:-
PROCEDURE translate()
JSONRequest is a restRequest
JSONReponse is a restResponse
Stringtosend is UNICODE string
GOOGLE_KEY_TRANSLATE_API is a string = "MyAPIKEY"
JSONRequest.URL = "
https://translation.googleapis.com/language/translate/v2…
=" + GOOGLE_KEY_TRANSLATE_API
JSONRequest.Header["content-type"] = "application/x-www-form-urlencoded"
JSONRequest.Header["accept-encoding"] = "text/plain"
JSONRequest.Header["x-rapidapi-key"] = "AIzaSyCbBqJuGH6gAYxmGDryx7qnA_so15rvAS8"
JSONRequest.Header["x-rapidapi-host"] = "titanium-octane-320517"
JSONRequest.Header["useQueryString"] = True
JSONRequest.Content = [
{
"mimetype": "Text/plain"
"q": "Hello world",
"source": "en",
"target": "es",
"model": ""
}
]
JSONReponse = RESTSend(JSONRequest)
IF ErrorOccurred THEN
Error(ErrorInfo(errFullDetails))
RETURN ""
ELSE
HTM_Result = UTF8ToAnsi(JSONReponse.Content)
END
v = JSONToVariant(JSONReponse.. Content)
RETURN "" + v.data.translations[1].translatedText
Has anyone done this successfully and if so would they be prepared to share the code whilst I still have some hair left!
Thanks
Simon
--
Simon Phillips
OtterReg Software
Denunciar
0
0
kchanog
#3
Membro registado
2 mensagems
Publicado em agosto, 03 2021 - 8:37 AM
Merci
--
Mon site internet -
https://www.clickstest.com/
Denunciar
0
0
→ Voltar para WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (versões anteriores)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Tipo de Pesquisa
Apenas tópicos
Todas as mensagens
Período de pesquisa
Qualquer momento
Última hora
Últimas 24 horas
Semana passada
Mês passado
Ano passado
Cancelar
Pré-visualização da sua mensagem
Adicionar imagem
Importar uma imagem de uma URL
Enviar uma imagem a partir do seu disco
Deixe um ficheiro ou clique em "Procurar ..."
ou
Cancelar
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Texto