FOROS PROFESIONALES
WINDEV
,
WEBDEV
y
WINDEV Mobile
Inicio
|
Mensajes recientes
|
Conéctese...
|
Desconectar
|
Español
Inicio
→
WINDEV 2024
→
Using restRequest to access Microsoft Translate
Using restRequest to access Microsoft Translate
Iniciado por Simon Phillips, 23,jul. 2021 13:42 - 2 respuestas
Conéctese…
Simon Phillips
#1
Publicado el 23,julio 2021 - 13:42
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
Informar
0
0
Simon PHILLIPS
#2
Miembro registrado
32 mensajes
Popularité : +1 (1 vote)
Publicado el 24,julio 2021 - 12:45
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
Informar
0
0
kchanog
#3
Miembro registrado
2 mensajes
Publicado el 03,agosto 2021 - 08:37
Merci
--
Mon site internet -
https://www.clickstest.com/
Informar
0
0
→ Volver a WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (versiones precedentes)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Búsqueda Tipo
Sólo temas
Todos los mensajes
Periodo Buscar
Cualquier fecha
Última hora
Última 24 horas
Última semana
Último mes
Último año
Cancelar
Vista previa del mensaje
Añadiendo una imagen
Importar una imagen desde una URL
Enviar una imagen desde un archivo de su disco
Arrastrar un archivo o click en "Examinar..."
o
Cancelar
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Texto