Text Translator

부분 유료
분류별 DEVISTY | 업데이트됨 1ヶ月前 | Translation
인기

9.9 / 10

지연 시간

564ms

서비스 수준

100%

Health Check

100%

모든 토론으로 돌아가기

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 1年前

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

Tks!

Rapid account: Gustavoloureiroramos
gustavoloureiroramos Commented 1年前

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 1年前

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

Thanks.

아래에 의견을 추가하고 토론에 참여하세요.

새 댓글을 게시하려면 로그인 / 가입