Giter VIP home page Giter VIP logo

Comments (5)

roisnir avatar roisnir commented on June 9, 2024

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.

Loopex2019 avatar Loopex2019 commented on June 9, 2024

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.

roisnir avatar roisnir commented on June 9, 2024

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.

Loopex2019 avatar Loopex2019 commented on June 9, 2024

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.

roisnir avatar roisnir commented on June 9, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.