I created an account via cloud for Google Translate, created an API key and got the credentials information. Api url works without any problems in Postman. I also created a react.js web project to test it and it works fine there too. However, when I integrate my React Native application, it gives an error and terminates the session in my application. I log in to my chat application again and try it, the same thing continues. [enter image description here](https://i.sstatic.net/8nLEsBTK.png)
const handleTranslate = async () => {
try {
const translatedConfessionText = await translateText(
selectedConfession.confess,
);
const translatedTitle = await translateText(selectedConfession.title);
setTranslatedConfessionText(translatedConfessionText);
setTranslatedTitle(translatedTitle);
} catch (error) {
console.error('Error translating text:', error);
}
};
const translateText = async text => {
try {
const response = await axios.post(
'https://translation.googleapis.com/language/translate/v2?key=********',
{
q: text,
source: 'tr',
target: 'en',
},
);
return response.data.data.translations[0].translatedText;
} catch (error) {
console.error('Error translating text:', error.response.data);
throw error;
}
};
<Text style={styles.modalText}>
{translatedConfessionText || selectedConfession?.confess}
</Text>
There is no problem with web or postman. enter image description here