getAccessToken method
Implementation
Future<Oauth> getAccessToken({required String apiKey, required String apiSecert}) async {
try {
var uri = Uri.parse(_URL_OAUTH);
var response = await http.post(uri, body: {'api_key': apiKey, 'api_secert': apiSecert}).timeout(const Duration(seconds: 10));
var data = json.decode(response.body);
if (data == null || data['error'] != null || response.statusCode != 200 || _isStatusCodeSuccess(data)) {
print(data);
return Future.value(Oauth(token: "", createAt: "", expired: "", isLongLive: false));
}
var token = data['data']['response']['data']['IsToken'];
var createAt = data['data']['response']['data']['Createat'];
var expired = data['data']['response']['data']['Expried'];
var isLongLive = data['data']['response']['data']['IsLonglive'];
return Future.value(Oauth(token: token, createAt: createAt, expired: expired, isLongLive: isLongLive));
} catch (exception) {
return Future.error(exception);
}
}