Text Translator

FREEMIUM
By DEVISTY | Updated 23 days ago | Translation
Popularity

9.9 / 10

Latency

801ms

Service Level

100%

Health Check

100%

Back to All Discussions

API returning a 403 error

I’m attempting to use this API in a Dart/Flutter code, but I’m getting a 403 error, here’s a snippet:

Future<List<String>> getLanguage() async {
var url = getURL;
final headers = getHeader;
var response = await http.get(Uri.parse(url), headers: headers);

if (response.statusCode == 200) {
  final responseBody = json.decode(response.body);
  final languages = responseBody['data']['languages'];
  final nameList = languages.map<String>((language) => language['name']).toList();
  return nameList;
} else {
  throw Exception('Failed to get languages with status: ${response.statusCode}');
}

This is getLanguage() method is later called in another class in order to fill two DropDownButtons, like this:

  Future<void> _initializeDropDownButtons() async {
final languages = await textTranslationMethods.getLanguage();
setState(() {
  _items = languages;
  _sourceDropDownValue = _items.first;
  _targetDropDownValue = _items.first;
  // print(_items);
});

}

Posting the whole code would get to large, but essentially I think there's a permission error. Maybe my account is unauthorized for some reason?
Rapid account: Gustavoloureiroramos
gustavoloureiroramos Commented a year ago

It’s working now, I’m not sure exactly what changed but it no longer matters.

Tks!

Rapid account: Gustavoloureiroramos
gustavoloureiroramos Commented a year ago

Sure, here’s the code of the file with the headers and constants, I just substituted my API Keys for proxys:

const String getURL = ‘https://text-translator2.p.rapidapi.com/getLanguages’;
const String translateURL = ‘https://text-translator2.p.rapidapi.com/translate’;

Map<String, String> getHeader = {
‘Accept-Encoding’: ‘application/gzip’,
‘X-RapidAPI-Key’: ‘hereIsMyAPIKey’,
‘X-RapidAPI-Host’: ‘text-translator2.p.rapidapi.com
};

Map<String, String> translateHeader = {
‘Accept-Encoding’: ‘application/gzip’,
‘content-type’: ‘application/x-www-form-urlencoded’,
‘X-RapidAPI-Key’: ‘hereIsMyAPIKey’,
‘X-RapidAPI-Host’: ‘text-translator2.p.rapidapi.com
};

Rapid account: Dickyagustin
dickyagustin Commented a year ago

Halo,
Can you show me the code snippet for the request header?
Make sure to include the X-RapidAPI-Key header

Thanks.

Join in the discussion - add comment below:

Login / Signup to post new comments