getAccountprofile method
Implementation
@override
Future<MinecraftAccountProfile> getAccountprofile() async {
if (_minecraftProfile != null) {
return _minecraftProfile!;
}
if (_minecraftToken == null) {
throw Exception('No Minecraft token available');
}
final response = await _httpClient.get(
Uri.parse('https://api.minecraftservices.com/minecraft/profile'),
headers: {'Authorization': 'Bearer $_minecraftToken'},
);
if (response.statusCode == 200) {
final jsonResponse = jsonDecode(response.body);
_minecraftProfile = MinecraftAccountProfile.fromJson(jsonResponse);
return _minecraftProfile!;
} else if (response.statusCode == 404) {
throw Exception(
'No Minecraft profile found. You may need to purchase the game.',
);
} else {
throw Exception('Failed to get Minecraft profile: ${response.body}');
}
}