getAccessToken method

Future<Response> getAccessToken({
  1. required String clientId,
  2. required String clientSecret,
  3. required String accountId,
})

Implementation

Future<Response> getAccessToken(
    {required String clientId,
    required String clientSecret,
    required String accountId}) async {
  final encoded = base64Url.encode(utf8.encode("$clientId:$clientSecret"));

  final url = ZoomConstants.authTokenUrl + accountId;

  final options = Options(
    headers: {
      "Authorization": "Basic $encoded",
    },
  );

  final data = {'client_id': clientId};

  try {
    final response = await dio.post(url, options: options, data: data);
    if (response.statusCode == 200) {
      return response;
    } else {
      throw Exception('Failed to fetch data: ${response.statusCode}');
    }
  } on DioException catch (e) {
    if (e.response?.statusCode == 404) {
      throw Exception('Something went wrong... ${e.message}');
    } else {
      throw Exception('Failed to log in: ${e.message}');
    }
  } catch (e) {
    throw Exception('Failed to fetch data: $e');
  }
}