对于抛出 403 状态代码的 HERE Places API(HERE sdk)有什么解决方案吗?

问题描述 投票:0回答:1

在我的 flutter 应用程序中,我实现了 HERE Places API(HERE sdk)来根据给定的查询字符串(查询)和硬编码的地理位置搜索地点。但它给出了 403 状态代码。

 Future<void> _searchPlaces(String query) async {
    print('Searching for: $query');
    final String apiKey =
        'API_KEY&size=50&result_types=place';
    final String baseUrl = 'https://places.ls.hereapi.com/places/v1/autosuggest';
    final response = await http.get(
      Uri.parse('$baseUrl?at=28.6925834,77.1526937&q=$query&apiKey=$apiKey'),
    );
    print('status code: ${response.statusCode}');
    if (response.statusCode == 200) {
      final Map<String, dynamic> data = json.decode(response.body);
      setState(() {
        _places = data['results'];
      });
    } else if (response.statusCode == 403) {
      throw Exception(
          'Failed to load places: Access forbidden. Check your API key or permissions.');
    } else {
      throw Exception('Failed to load places: ${response.statusCode}');
    }
  }
flutter http-status-code-403
1个回答
0
投票

var baseUrl = 'https://places.ls.hereapi.com/places/v1/autosuggest?'; var jsonRequest=jsonEncode(at=28.6925834,77.1526937&q=$query&apiKey=$apiKey);

现在通过您的方法获得响应

© www.soinside.com 2019 - 2024. All rights reserved.