Comments (5)
It occurs when you send too many requests rapidly. Spotify doesn't limit the number of calls, however, the rate is limited.
Coincidentally I'm added handling such cases (the PR will be posted soon).
Anyway, it shouldn't happen in most cases, maybe you set the limit too small when you use Paging?
can you post your code?
from spotify-dart.
Yes here is it :
static Future<String> getCategoriesId(String categoryName) async {
try {
final Iterable<Category> _categories =
await _spotifyApi.categories.list().all();
final Iterable<Category> _filteredCategory =
_categories.where((element) => element.name == categoryName);
final Category _firstCategory = _filteredCategory.toList()[0];
return _firstCategory.id;
} catch (e) {
Fluttertoast.showToast(msg: 'Failed to get category');
}
return null;
}
static Future<List<PlaylistSimple>> getPlayLists(String categoryName) async {
try {
final String _categoryId = await MusicAPI.getCategoriesId(categoryName);
final Pages<PlaylistSimple> _recommendations =
_spotifyApi.playlists.getByCategoryId(_categoryId);
final Iterable<PlaylistSimple> _playLists = await _recommendations.all();
return _playLists.toList();
} catch (e) {
print(e);
Fluttertoast.showToast(msg: 'Failed to get playlists');
}
return null;
}
static Future<List<Track>> getRecommendations(String categoryName) async {
try {
final List<PlaylistSimple> _playLists =
await MusicAPI.getPlayLists(categoryName);
List<Track> _tracks = [];
for (PlaylistSimple playList in _playLists) {
_spotifyApi.playlists.getTracksByPlaylistId(playList.id).all().then(
(value) => _tracks = value.toList(),
);
}
return _tracks;
} catch (e) {
print(e);
Fluttertoast.showToast(msg: 'Failed to get music tracks');
}
return null;
}```
from spotify-dart.
I guess the exception is raised on
_spotifyApi.playlists.getTracksByPlaylistId(playList.id).all().then(
(value) => _tracks = value.toList(),
);
due to the requests sent in the for loop. How many playlists _playlists
contains?
Do you really need to get all the tracks of all of the playlist all in once?
from spotify-dart.
I removed the for loop and requested just the first playlist but this error still occurs :
static Future<List<Track>> getRecommendations(String categoryName) async {
try {
final List<PlaylistSimple> _playLists =
await MusicAPI.getPlayLists(categoryName);
List<Track> _tracks = [];
_spotifyApi.playlists.getTracksByPlaylistId(_playLists[0].id).all().then(
(value) => _tracks = value.toList(),
);
return _tracks;
} catch (e) {
print(e);
Fluttertoast.showToast(msg: 'Failed to get music tracks');
}
from spotify-dart.
That's pretty weird. add an await Future.delayed()
for a few seconds between getPlayLists
and getTracksByPlaylistId
to check if the exception is raised because they are called one after the other or maybe it raised inside the .all()
and tell what happened.
And another check, add a print('sending request')
in getRecommendations
to make sure there aren't any other loop the calls this function.
If this problem continues after those checks, the PR should solve it.
from spotify-dart.
Related Issues (20)
- `DeviceType` 'Smartwatch' is missing
- Playlist info, tracks and artists HOT 10
- Support `episode`s when retrieving items from playlist HOT 1
- Artist Info HOT 2
- startOrResume throws error code 400 (malformed json) HOT 5
- Add debug tools HOT 1
- FormatException HOT 13
- Spotify Client Authentication HOT 3
- Log In Account HOT 13
- 404 Device not found (and unhandled exception) HOT 1
- Bug: `artists.get` throwing exception "type 'double' is not a subtype of type 'int?' in type cast" HOT 20
- An album play something else! HOT 4
- [Question]: Is it possible to have my flutter client read data from my own account HOT 1
- Include `BaseResponseWithUrl` HOT 1
- Expose `codeVerifier` when building `AuthorizationCodeGrant` HOT 4
- Bug: startWithTracks results in error 400 HOT 1
- Bug: `album.tracks` throwing exception "type 'double' is not a subtype of type 'int?' in type cast" HOT 3
- Enable `createToJson` for the models
- Better handling of list of IDs when there are more than 50 HOT 8
- Throw `ArgumentError`s when `assert`ions fail HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from spotify-dart.