PROFESSIONAL NEWSGROUPS
WINDEV
,
WEBDEV
and
WINDEV Mobile
Home
|
Recent messages
|
Connect
|
Sign out
|
English
Home
→
WINDEV 2024
→
Using restRequest to access Microsoft Translate
Using restRequest to access Microsoft Translate
Started by Simon Phillips, Jul., 23 2021 1:42 PM - 2 replies
Connect yourself…
Simon Phillips
#1
Posted on July, 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
Report
0
0
Simon PHILLIPS
#2
Registered member
32 messages
Popularité : +1 (1 vote)
Posted on July, 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
Report
0
0
kchanog
#3
Registered member
2 messages
Posted on August, 03 2021 - 8:37 AM
Merci
--
Mon site internet -
https://www.clickstest.com/
Report
0
0
→ Go back to WINDEV 2024
WINDEV 2024
WEBDEV 2024
WINDEV Mobile 2024
WINDEV (earlier versions)
Français
English
Español
Portuguesa
Close this window
Search type
Only topics
All the messages
Search period
Any time
Past hour
Past 24 hours
Past week
Past month
Past year
Cancel
Preview of your message
Adding an image
Import an image from a URL
Send an image from a file of your disk
Drop a file or click "Browse..."
or
Cancel
0%
WLanguage
SQL
XML, HTML
JAVA, Javascript
Text