getUsername method

Future<String> getUsername({
  1. required String accesstoken,
  2. required String userid,
})

Implementation

Future<String> getUsername({
  required String accesstoken,
  required String userid,
}) async {
  try {
    String scopes = usernameFields.join(',');
    final response = await http.get(
      Uri.parse(
        'https://graph.instagram.com/$userid?fields=$scopes&access_token=$accesstoken',
      ),
    );
    final body = jsonDecode(response.body);
    debugPrint('body: $body');
    return body['username'];
  } catch (e) {
    debugPrint('Error: $e');
    throw Exception(e);
  }
}