Hello? By any chance, can the Google Translate API v2 be used in the frontend?
Initially, I thought the Google Translate API v2 couldn't be used in the frontend due to CORS issues. However, when I input the code below into the browser, the API is being called normally.
I'm curious if it's okay to call the API directly from the browser from the beginning.
const url = 'https://translation.googleapis.com/language/translate/v2?key={{API_KEY}}';
const headers = {
'Content-Type': 'application/json; charset=utf-8',
};
fetch(url, {
method: 'POST',
headers: headers,
body: JSON.stringify({
"q": ["Hello world", "My name is Jeff"],
"target": "de"
}),
})
.then((response) => response.json())
.then((data) => console.log(data))
.catch((error) => console.error(error));
Good day @cress00,
Welcome to Google Cloud Community!
As stated in the Cloud Translation API Documentation, cloud translation API can be integrated into your website or application, so this is correct. If there are CORS issues encountered, this might be an authentication problem. You can check this documentation for more information: https://cloud.google.com/translate/docs/reference/rest
Hope this helps!