FORUMS PROFESSIONNELS
WINDEV
,
WEBDEV
et
WINDEV Mobile
Accueil
|
Messages récents
|
Connexion
|
Déconnexion
|
Français
Accueil
→
WINDEV 2024
→
Using restRequest to access Microsoft Translate
Using restRequest to access Microsoft Translate
Débuté par Simon Phillips, 23 juil. 2021 13:42 - 2 réponses
Connectez-vous…
Simon Phillips
#1
Posté le 23 juillet 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
Signaler
0
0
Simon PHILLIPS
#2
Membre enregistré
32 messages
Popularité : +1 (1 vote)
Posté le 24 juillet 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
Signaler
0
0
kchanog
#3
Membre enregistré
2 messages
Posté le 03 août 2021 - 08:37
Merci
--
Mon site internet -
https://www.clickstest.com/
Signaler
0
0
→ Revenir à WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (précédentes versions)
Français
English
Español
Portuguesa
Fermer cette fenêtre
Type de recherche
Uniquement les sujets
Tous les messages
Période de recherche
Date indifférente
Moins d'une heure
Moins de 24 heures
Moins d'une semaine
Moins d'un mois
Moins d'un an
Annuler
Aperçu de votre message
Ajouter une image
Importer une image depuis une URL
Envoyer une image depuis un fichier de votre disque
Déposez ici un fichier ou cliquez sur "Parcourir..."
ou
Annuler
0%
WLangage
SQL
XML, HTML
JAVA, Javascript
Texte