I have a REST API that I need to access from a Flutter app. It is from the Spotify Web API. The terminal command that I would use for this is
curl -X "GET" "https://api.spotify.com/v1/me/following?
type=artist&limit=50" -H "Accept: application/json" -H "Content-Type:
application/json" -H "Authorization: Bearer (ACCESS TOKEN)"
Which works. In Flutter, I have imported the import 'package:http/http.dart' as http package and import 'dart:convert'. I also have a Future that is as follows
Future<String> getData() async {
http.Response response = await http.get(
Uri.https("api.spotify.com", "v1/me/following?type=artist&limit=50"),
headers: {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization":
"Bearer (ACCESS TOKEN)"
});
Map dataMap = jsonDecode(response.body);
print(dataMap);
}
This results in {error: {status: 404, message: Service not found}} which is weird since it works perfectly in terminal. What am I doing wrong?