Closed addreeh closed 11 months ago
Seems like you hit a quota and got rate limited. But maybe we need to think about some library level handling of such a situation.
What it means for you right now is, that you need to wait until you can make a request again. In the Developer Dashboard you should be able to see your current volume.
Its probably that i hitted a quota because I tried a lot of things yesterday, but my question is if I deploy an app how can I handle these type of problems? Maybe creating another app and changing between them?
@addreeh You could show the user a message, that the app is currently not usable and that he/she should try it again later. I suggest to check the code for unnecessary requests (sometimes they are done in some for
-loops) and look for alternatives (e.g. instead of requesting all albums for each artist, you could collect each albumId
for each artist and do a getSeveralAlbums
request). That way you would reduce requests.
Mmmm yes, is so probably that i am doing request that are unnecessary, I would glad if you could check my code and tell me if I can resume or delete something, if you don't have time close the issue, I understand that this is not the place for that. Thanks for the support.
while (true) {
try {
var tracks = await spotifyApi.playlists
.getTracksByPlaylistId(playlistObject.id)
.getPage(limit, offset);
...
}
GET
ting one Page
at a time. This could be done with ListView
s that allow to fetch more data once the end of the list is reached. Unfortunately I forgot the proper name of those lists, but with a quich search you would be able to find it._getFullArtist() async {
List<spotify.Artist> artists = [];
for (var artist in playlistArtists) {
try {
var newArtist = await spotifyApi.artists.get(artist.id);
artists.add(newArtist);
} catch (e) { ... }
return artists;
}
spotify.artists.list()
here instead of requesting each artist individually. So in your case it would look like this:_getFullArtist() async {
// converting list of artists into list of artist id's
var artistIds = playlistArtists.map((artist) => artist.id);
// bulk retrieve artist information saving you the for-loop
return await spotifyApi.artists.list(artistIds);
}
Hope it helps :)
Seems like you hit a quota and got rate limited. But maybe we need to think about some library level handling of such a situation.
@rinukkusu Maybe tracking the number of requests?
My purpose is to do an app to track a playlist, it shows the percentage of songs that each artist has, because of that I have to get all the tracks and then I have to get each artist of each song, because of that i have to use a lot of loops that makes the app slow, but Im sure that if I would know all the methods of the library it will be faster jajaja
@addreeh You can check out the wiki-page, where all implemented endpoints are listed.
ok, thank you, finally can you tell me if the way i get all the tracks of the playlist is the correct?
I tried your app out, and retrieving each track and having a statistic like that, is also the only way I would come up with. But I think, you could optimize some of your for
loops, for example
...
int offset = 0;
int limit = 100;
while (true) {
try {
var tracks = await spotifyApi.playlists
.getTracksByPlaylistId(playlistObject?.id ?? '')
.getPage(limit, offset);
if (tracks.items != null && tracks.items!.isNotEmpty) {
try {
songs.addAll(tracks!.items); //<-- just use addAll instead of another for loop.
offset += limit;
} catch (e) {
offset = songs.length;
}
And you also could play around with the dart collection api. It has some methods that could make you remove some of your for
loops.
I will try it, thank you.
@addreeh can this issue be closed?
Sorry, I didnt have time to try those changes, but yes, can be clossed as completed. Thanks.
Hi guys, any idea about this issue:
FormatException: Unexpected character (at character 1) Too many requests
I dont know if is an API timeout, if it is which will be the better solution?