focasds
(focasds)
August 13, 2020, 7:02pm
#1
Hello, hope you are feeling well! I am stuck using Google’s API . I read everything already, first idk what happens to the given link that it doesn’t work, second idk which one should I use between:
HttpService:Post()
or
HttpService:RequestAsync()
Which one should I use to make the request and what’s the proper link for it?
Method: projects.translateText | Cloud Translation | Google Cloud
1 Like
varjoy
(variable)
August 13, 2020, 7:05pm
#3
:RequestAsync() to reqest data, clearly.
You should find info on their docs, check their API, you’ll find answers!
2 Likes
focasds
(focasds)
August 13, 2020, 7:05pm
#4
I used the link but it doesn’t work…
1 Like
focasds
(focasds)
August 13, 2020, 7:07pm
#5
In case you want to know what the error is when I use that link is: 15:06:46.949 - HttpError: InvalidUrl
1 Like
railworks2
(railworks2)
August 13, 2020, 7:07pm
#6
Did you issue a POST request? What is the HTTP status code? Did you follow the syntax requirements?
See: https://github.com/googleapis/googleapis/blob/master/google/api/http.proto for those requirements.
Have you tried official support? How to get help | Google APIs Explorer | Google for Developers
2 Likes
focasds
(focasds)
August 13, 2020, 7:08pm
#7
local HttpService = game:GetService("HttpService")
local TranslatorLink = "https://translation.googleapis.com/v3/{parent=projects/*}:translateText"
local Data = {
contents = {
"Hello World",
},
sourceLanguageCode = "en",
targetLanguageCode = "sr",
}
Data = HttpService:JSONEncode(Data)
wait(3)
local TranslatedString = HttpService:PostAsync(TranslatorLink, Data)
TranslatedString = HttpService:JSONDecode(TranslatedString).translatedText
print(TranslatedString)
This the script I have, while following everything they said.
1 Like
railworks2
(railworks2)
August 13, 2020, 7:10pm
#8
I presume you’ve removed the API information.
If not,
Format: projects/{project-number-or-id}
or projects/{project-number-or-id}/locations/{location-id}
.
For global calls, use projects/{project-number-or-id}/locations/global
or projects/{project-number-or-id}
.
Refer to this and adapt as required.
2 Likes
focasds
(focasds)
August 13, 2020, 7:13pm
#9
The error I am currently having is the one of the URL, I can’t check if I have errors setting up, if the link doesn’t proceed…
1 Like
See:
You must change the asterisk in your URL to a project’s id. You can create a project on the Cloud Resource Manager dashboard and see it’s id there.
FYI: You’re missing the mimeType in your request body, this should be "text/plain"
.
1 Like
focasds
(focasds)
August 13, 2020, 7:50pm
#11
Does it cost to create a project?
Nope, I have one for Firebase which doesn’t cost anything at all.
focasds
(focasds)
August 13, 2020, 7:53pm
#13
How do I create a project there, I have to click Get Started ?