Giter VIP home page Giter VIP logo

spotify-dart's Introduction

spotify-dart Pub Dart CI

A dart library for interfacing with the Spotify API.

Usage

Simple Example

final credentials = SpotifyApiCredentials(clientId, clientSecret);
final spotify = SpotifyApi(credentials);
final artist = await spotify.artists.get('0OdUWJ0sBjDrqHygGUXeCF');

Authorization

For detailed information regarding authorization, client credentials flow and more, see the wiki.

Features and bugs

Please file feature requests and bugs at the issue tracker.

Development

Generating JSON Serializers

Run dart run build_runner build to generate JSON serializers via json_serializable. Run dart run build_runner watch to continuously rebuild serializers in the background when files are updated.

Running tests

Run dart test to run all of the tests in test/spotify_test.dart.

Running example code

Run dart example/example to run the example code. You'll need to modify example/example.dart to use your Spotify client ID and secret.

If you would like to run the example that accesses your user data (such as currently playing song etc.), run pub run example/example_auth.dart. There, you are requested to enter your redirect url (see the comment above redirectUri). After that, you are requested to call a given url (or paste it into your browser). That url will do a redirect in your browser. You should copy and paste this redirected url into your console to see the currently playing song and your available devices.

spotify-dart's People

Contributors

brunojurkovic avatar chances avatar deandreamatias avatar dependabot[bot] avatar doodlezucc avatar ebarnsli avatar elmdecoste avatar espiegelberg avatar evaqum avatar fotidim avatar gmpassos avatar hayribakici avatar ikatsuba avatar ivansupervan avatar jzhan10 avatar krtirtho avatar levihassel avatar nrubin29 avatar nzoschke avatar rakeshteamswork avatar rinukkusu avatar roisnir avatar scarnett avatar stefanoromanello avatar volgin avatar voxar avatar wesleybatista avatar willroxby avatar yoannmtr avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

spotify-dart's Issues

Refresh Token

Hi, I would like to know how to use the refresh token. Currently I can log in and save the credentials but after about 10 minutes the refresh token expires and I need to ask the user another login. Is there a way to ask to the API a new token when the old one expires without asking the login again?

In particular, this is the error I get when I try to create a SpotifyApi class by using the saved credentials:

Exception has occurred.
AuthorizationException (OAuth authorization error (invalid_grant): Refresh token revoked.)

Make AuthorizationException from SpotifyApi ctor catchable

I'd like to add that the exception above doesn't seem to be able to be caught:

try {
    this.api = SpotifyApi(creds);
} on AuthorizationException {
    this.api = null;
}

still throws the exception. Would be great to be able to catch the exception, at least.

How to create a user authenticated instance of SpotifyApi from accessToken but without secret?

Is this library meant for client applications? It seems every way to get an instance of the SpotifyApi requires clientSecret, which Spotify advises you hide behind a server and don't ship in client code. Ideally, I'd like a way to get an instance of SpotifyApi from just an accessToken and/or refreshToken without needing the secret. I see issues asking similar things, but none of them have a full example on how to do this.

I'm working on a Flutter client app that interacts with Spotify. Following Spotify's documentation, I've implemented the Authorization Code Flow where my client knows my Spotify app's clientId, I send user to the spotify url to grant access, it redirects to my app where I get the authorization code. At this point, I send the code to my server, where the server uses the code, client id and secret to get a refresh and access token and sends it back to the client. Now, with the access token I can make successful authed requests to Spotify's apis as the user through raw requests (that is, outside of using this library). But I don't see a way to use this library from just an accessToken/refreshToken when really you should be able to.

Mixin Classes are not generated.

Hi,

when I try to let dart build the generated json-serializer code with pub run build_runner build, the model classes become erroneous, because all the the _$...Mixin classes are not generated. What is the best way to let dart build the mixins as well?

Thanks for this library again:)
cheers

Search returns Album, but json only contains SimplifiedAlbum

First, thanks for the great library! It already made my life easier. :)

I got bitten by this bug using the search API and searching for albums. I was accessing the popularity field and got a null pointer exception.

The Spotify API Reference, states, that simplified album objects are returned from search:
https://developer.spotify.com/documentation/web-api/reference-beta/#category-search

So I think that trying to detect Simplified or Full Album types automatically using this heuristic is problematic. We should stick to types stated in reference documentation here.

json.containsKey('release_date')

Getting type 'Null' is not a subtype of type 'Map<String, dynamic>' on the example code

Hello, i have a little problem.

I've copied the example script from here : https://pub.dev/packages/spotify/example , just i've kept only the search section. None of the code is changed. Everything is original.

My code is :


  var credentials = SpotifyApiCredentials('id','secret');
  var spotify = SpotifyApi(credentials);


  print("\nSearching for \'Metallica\':");
  var search = await spotify.search
      .get('metallica')
      .first(2)
      .catchError((err) => print((err as SpotifyException).message));
  if (search == null) {
    return;
  }
  search.forEach((pages) {
    pages.items!.forEach((item) {
      if (item is PlaylistSimple) {
        print('Playlist: \n'
            'id: ${item.id}\n'
            'name: ${item.name}:\n'
            'collaborative: ${item.collaborative}\n'
            'href: ${item.href}\n'
            'trackslink: ${item.tracksLink!.href}\n'
            'owner: ${item.owner}\n'
            'public: ${item.owner}\n'
            'snapshotId: ${item.snapshotId}\n'
            'type: ${item.type}\n'
            'uri: ${item.uri}\n'
            'images: ${item.images!.length}\n'
            '-------------------------------');
      }
      if (item is Artist) {
        print('Artist: \n'
            'id: ${item.id}\n'
            'name: ${item.name}\n'
            'href: ${item.href}\n'
            'type: ${item.type}\n'
            'uri: ${item.uri}\n'
            '-------------------------------');
      }
      if (item is TrackSimple) {
        print('Track:\n'
            'id: ${item.id}\n'
            'name: ${item.name}\n'
            'href: ${item.href}\n'
            'type: ${item.type}\n'
            'uri: ${item.uri}\n'
            'isPlayable: ${item.isPlayable}\n'
            'artists: ${item.artists!.length}\n'
            'availableMarkets: ${item.availableMarkets!.length}\n'
            'discNumber: ${item.discNumber}\n'
            'trackNumber: ${item.trackNumber}\n'
            'explicit: ${item.explicit}\n'
            '-------------------------------');
      }
      if (item is AlbumSimple) {
        print('Album:\n'
            'id: ${item.id}\n'
            'name: ${item.name}\n'
            'href: ${item.href}\n'
            'type: ${item.type}\n'
            'uri: ${item.uri}\n'
            'albumType: ${item.albumType}\n'
            'artists: ${item.artists!.length}\n'
            'availableMarkets: ${item.availableMarkets!.length}\n'
            'images: ${item.images!.length}\n'
            'releaseDate: ${item.releaseDate}\n'
            'releaseDatePrecision: ${item.releaseDatePrecision}\n'
            '-------------------------------');
      }
    });
  });

  var relatedArtists =
  await spotify.artists.relatedArtists('0OdUWJ0sBjDrqHygGUXeCF');
  print('\nRelated Artists: ${relatedArtists.length}');

  credentials = await spotify.getCredentials();
  print('\nCredentials:');
  print('Client Id: ${credentials.clientId}');
  print('Access Token: ${credentials.accessToken}');
  print('Credentials Expired: ${credentials.isExpired}');
}

I keep getting the songs, which is a good thing, but i have this error as well. I'm still a beginner on dart, so i dont really know how to solve this one.

-------------------------------
Track:
id: 0LAcM6I7ijW4VVW0aytl1t
name: One (Remastered)
href: https://api.spotify.com/v1/tracks/0LAcM6I7ijW4VVW0aytl1t
type: track
uri: spotify:track:0LAcM6I7ijW4VVW0aytl1t
isPlayable: null
artists: 1
availableMarkets: 2
discNumber: 1
trackNumber: 4
explicit: false
-------------------------------
Unhandled exception:
type 'Null' is not a subtype of type 'Map<String, dynamic>'
#0      Search.get.<anonymous closure> (package:spotify/src/endpoints/search.dart:40:40)
#1      MappedListIterable.elementAt (dart:_internal/iterable.dart:413:31)
#2      ListIterable.forEach (dart:_internal/iterable.dart:39:14)
#3      main.<anonymous closure> (package:playit/scripts/spotify.dart:25:18)
#4      List.forEach (dart:core-patch/growable_array.dart:433:8)
#5      main (package:playit/scripts/spotify.dart:24:10)
<asynchronous suspension>

Thanks for reading me

How to play a song?

This package doesn't have this api yet but even when I do it myself I'm left scratching my head on how to play a song. Following the Spotify API reference, I have:

Future<void> play([String uri]) async {
  if (client != null) {
    try {
      await client.put('https://api.spotify.com/v1/me/player/play', body: {
        'context_uri': uri,
      });
    } on SpotifyException catch (e) {
      print('${e.status}: ${e.message}');
    }
  } else {
    print('No client available.');
  }
}

but when I call spotify.users.currentlyPlaying() afterwards player.isPlaying is always false. Not to mention I have no clue where to get the actual stream so I can pass it to an audio player.

Spotify Charts API

Hi is there a way to access chart data like accessing the top tracks in each country or on a global level ?

AlbumSimple doesn't include release date

Thanks for the great package!

I've noticed that the AlbumSimple object (for example the album field on a Track object) doesn't include any release date information.

Spotify Web API docs for album object (simplified) say this object should include release_date and release_date_precision.

Where is Track.external_ids.isrc?

I'm relying on ISRC to identify tracks and noticed that you have omitted the external_ids object from the track object. What was the reasoning behind this?

BTW, congrats and thanks for the excellent library!

Add date-based paging support to EndpointPaging

In PR #66 date-based paging has been added to the me.recentlyPlayed() endpoint.
As a developer I'd like to use this kind of paging in other places as well, so it would be great to have it implemented in EndpointPaging itself directly. We'll probably need seperate paging classes for offset- and date-based paging.

Playlist support

Hi! I found your library while playing with the Spotify API, I just wanted to make sure that I'm not missing something and playlists just aren't supported at the moment (maybe I don't know how to use them, really).
Great work!

Search API provides full Album info but only SimpleAlbum is returned

I don't know if the search api has changed recently or if this is true for only some queries but I'm seeing full album info being returned from track searches. The library should detect which type is returned and return the appropriate model rather than assuming AlbumSimple.

https://api.spotify.com/v1/search?q=track:sunny+artist:pat+martino&type=track returns (summarized):

    "tracks": {
        "href": "https://api.spotify.com/v1/search?query=track%3Asunny+artist%3Apat+martino&type=track&offset=0&limit=20",
        "items": [
            {
                "album": {
                    "album_type": "album",
                    "artists": [
                        {
                            "external_urls": {
                                "spotify": "https://open.spotify.com/artist/4DlMMgnldzX6OkCskmeGKz"
                            },
                            "href": "https://api.spotify.com/v1/artists/4DlMMgnldzX6OkCskmeGKz",
                            "id": "4DlMMgnldzX6OkCskmeGKz",
                            "name": "Pat Martino",
                            "type": "artist",
                            "uri": "spotify:artist:4DlMMgnldzX6OkCskmeGKz"
                        }
                    ],
                    "available_markets": [
                        ...
                    ],
                    "external_urls": {
                        "spotify": "https://open.spotify.com/album/6R8qLTLbNFxzfBoavYUCXy"
                    },
                    "href": "https://api.spotify.com/v1/albums/6R8qLTLbNFxzfBoavYUCXy",
                    "id": "6R8qLTLbNFxzfBoavYUCXy",
                    "images": [
                        {
                            "height": 640,
                            "url": "https://i.scdn.co/image/33e8507aca73dbac105ab66692166efa57ef5e93",
                            "width": 640
                        },
                        {
                            "height": 300,
                            "url": "https://i.scdn.co/image/2b0da092447fa0f56bb14c04846e81f1668d9a2d",
                            "width": 300
                        },
                        {
                            "height": 64,
                            "url": "https://i.scdn.co/image/41ca471da9baf47a7498b12d01c1784120894103",
                            "width": 64
                        }
                    ],
                    "name": "Cream",
                    "release_date": "1997-10-21",
                    "release_date_precision": "day",
                    "total_tracks": 10,
                    "type": "album",
                    "uri": "spotify:album:6R8qLTLbNFxzfBoavYUCXy"
                },
                "artists": [
                    {
                        "external_urls": {
                            "spotify": "https://open.spotify.com/artist/4DlMMgnldzX6OkCskmeGKz"
                        },
                        "href": "https://api.spotify.com/v1/artists/4DlMMgnldzX6OkCskmeGKz",
                        "id": "4DlMMgnldzX6OkCskmeGKz",
                        "name": "Pat Martino",
                        "type": "artist",
                        "uri": "spotify:artist:4DlMMgnldzX6OkCskmeGKz"
                    }
                ],
                "available_markets": [
                    ...
                ],
                "disc_number": 1,
                "duration_ms": 628186,
                "explicit": false,
                "external_ids": {
                    "isrc": "USSJ10904865"
                },
                "external_urls": {
                    "spotify": "https://open.spotify.com/track/6xHcMss02s14r2EdXLEqhk"
                },
                "href": "https://api.spotify.com/v1/tracks/6xHcMss02s14r2EdXLEqhk",
                "id": "6xHcMss02s14r2EdXLEqhk",
                "is_local": false,
                "name": "Sunny",
                "popularity": 35,
                "preview_url": null,
                "track_number": 2,
                "type": "track",
                "uri": "spotify:track:6xHcMss02s14r2EdXLEqhk"
            },

Update Documentation

Hi,

is there any better documentation on how to use this library through OAuth? It seems like the README.md and the code are inconsistent. It would be nice to test certain features I am currently developing before merging.

Added "market" parameter

I need to get the search results in Japanese, so I want to add "market=JP" to the parameter.
Is there any way?

Example by using recommendations

Hi can you provide an example by using spotify recommendation , because i struggle in the mean :
Here is my code :

static Future<List<TrackSimple>> getRecommendations() async {
    try {
      final Recommendations _recommendations =
          await _spotifyApi.recommendations.get(
        limit: 50,
        seedArtists: [],
      );
      final List<TrackSimple> _tracks = _recommendations.tracks;
      return _tracks;
    } catch (e) {
      print(e);
      Fluttertoast.showToast(msg: 'Failed to get Music');
    }
    return null;
  }

Error fetching playlists

I'm testing my code with 70+ playlists and in some of them when I try to get the tracks by using getTracksByPlaylistId I get a broken list (Iterable) see https://i.imgur.com/T3Tyt38.png. It seems that it starts to put some tracks but can't finish the list.

I've done some debug in the sdk code and when the code is parsing each song of the playlist in the method "Track _$TrackFromJson(Map<String, dynamic> json)" present in _models.g.dart at some point for one song of the playlist the parameter json is null.

And when I try to read the length of the Iterable returned by getTracksByPlaylistId I get:

Exception has occurred. NoSuchMethodError (NoSuchMethodError: The method '[]' was called on null. Receiver: null Tried calling: []("album"))

but the song that get a null json object has an album and it is not a podcast in the playlist.

Ps: this occurs with 4/5 playlists over the 70+

Update: the getPage method works correctly for every page and the problem seems to be in this pages.expand:

  Future<Iterable<T>> all([int limit = defaultLimit]) {
 
    return stream(limit)
        .map((page) => page.items)
        .toList()
        .then((pages) {
          Iterable<T> all = pages.expand((page) => page);
          return all;
        } );
  }

which returns a broken iterable

Also, for avoiding the api rate limit is there a quicker way to get all the songs of all playlist or the only way is to fetch each playlist and use getTracksByPlaylistId?

Search not working

I have spotify_io imported like

import 'package:spotify/spotify_io.dart';

Copied the search from the examples directory on this repo

var credentials =
    new SpotifyApiCredentials(spotifyClientId, spotifyClientSecret);
var spotify = new SpotifyApi(credentials);
var search = await spotify.search
    .get("metallica")
    .first(2)
    .catchError((err) => print((err as SpotifyException).message));

And I get a couple errors, the first one seems like a pretty simple fix:

  1. [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type '_TypeError' is not a subtype of type 'SpotifyException' in type cast - this error can be fixed by removing the as SpotifyException cast. I first solved the issue by simply removing the catchError method, which revealed the second bug.
[ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: type 'String' is not a subtype of type 'Map<String, dynamic>'
E/flutter ( 5063): #0      SpotifyApi.handleErrors      package:spotify/src/spotify_io.dart:37
E/flutter ( 5063): #1      SpotifyApi._postImpl         package:spotify/src/spotify_io.dart:21

I dug into this one a bit, but I'm pretty new to Dart/Flutter in general so I couldn't figure out a fix. I believe I traced it, at least, to a line in endpoint_paging.dart - specifically line 163. It seems the _get method is where this bug is actually being generated - I can get a breakpoint to hit on var jsonString = await _api._get(path);, but if I remove it and add one to the next line (var map = json.decode(jsonString);), it never gets hit. I also can't get breakpoints to work in that _get method, so I think this is pretty close to where the bug is coming from, but I'm currently stuck scratching my head.

spotify 0.5.1 version still on pub.dev

Any plans to add the new version with null safety stuff to pub.dev? I'm really waiting for this. Also I could help with this library if you guys allow me.

Add support for currently-playing endpoint

Hey, I would like to have the currently-playing endpoint working on this package for a personal project that I have in mind.

_It is my first time actually doing something with Dart and I think I managed to get something. Will open the PR later on _

Issue in getting list of AudioFeatures for multiple trackIds

When I try to get the audioFeature for single trackId , it works fine.
This code returns correct result and works fine:
var trackFeatures = await spotifyApi.audioFeatures.get("Single 1 spotify id");

But if I try to get list of audioFeatures for multiple trackIds I am getting exception using below code:
List ids = ["track id 1 from Spotify", "track id 2 from Spotify" ];
var trackFeatures = await spotifyApi.audioFeatures.list(ids);

This is the stacktrace :

Screenshot 2020-04-21 at 8 27 33 PM

The error is here in audio_features.dart

 Future<Iterable<AudioFeature>> list(Iterable<String> trackIds) async {
    var jsonString = await _api._get('$_path?ids=${trackIds.join(',')}');
    var map = json.decode(jsonString);

var artistsMap = map['audio-features'] as Iterable<dynamic>;     ----< map is null >---
return artistsMap.map((m) => AudioFeature.fromJson(m));

}

get tracks list from a playlist URI

There's a way to get tracklist from a playlist URI like spotify:playlist:37i9dQZF1DX8wCc28V2cVW or via playlist id like for spotify.tracks.get(trackid) ?
i found this package very usefull so thanks for sharing this.

Currently Playing stream?

Apologies in advance for my ignorance...

Is it possible to receive a Currently Playing stream that is updated only when there's a change? For example, when a track finishes and a new one begins; or when a track is paused or restarted? (I guess I'm asking if there's a pubsub client for the spotify api, or something like that.)

At the moment I'm polling spotifyApi.me.currentlyPlaying() every three seconds, which is not ideal.

Many thanks

Nic

OAuth2 credentials have expired and can't be refreshed

flutter: 
#0      Client.send (package:oauth2/src/client.dart:109:36)
#1      BaseClient._sendUnstreamed (package:http/src/base_client.dart:93:38)
#2      BaseClient.get (package:http/src/base_client.dart:27:7)
#3      SpotifyApiBase._getImpl.<anonymous closure> (package:spotify/src/spotify_base.dart:152:31)
<asynchronous suspension>
#4      SpotifyApiBase._requestWrapper (package:spotify/src/spotify_base.dart:185:29)
<asynchronous suspension>
#5      SpotifyApiBase._getImpl (package:spotify/src/spotify_base.dart:151:12)

version: 0.7.0
How should this be fixed?

Spotify client from refresh token

#28 just landed, and I'd like the ability to create a client from a refresh token. Basically, I have a database with user refresh tokens, and I'd like to take a user's refresh token and construct an API instance using it. Could we add a SpotifyApiBase.fromRefreshToken()?

@roisnir

User's Following Artists api not working

The method .me.following(FollowingType.artist) is not working because when _parseBundledPage tries to create a new Page it cant calculate isLast because the APIs are not returning the offset.

[Error] API rate limit exceeded

Hi i faced an error while fetching music tracks an there is it :
`
E/flutter ( 877): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Error Code: 429
E/flutter ( 877): API rate limit exceeded
E/flutter ( 877): #0 SpotifyApiBase.handleErrors
package:spotify/src/spotify_base.dart:134
E/flutter ( 877): #1 SpotifyApiBase._getImpl
package:spotify/src/spotify_base.dart:100
E/flutter ( 877):
E/flutter ( 877): #2 SpotifyApiBase._get
package:spotify/src/spotify_base.dart:83
E/flutter ( 877): #3 Pages.getPage
package:spotify/…/endpoints/endpoint_paging.dart:143
E/flutter ( 877): #4 Pages.stream.handlePageAndGetNext
package:spotify/…/endpoints/endpoint_paging.dart:114
E/flutter ( 877): #5 _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter ( 877): #6 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter ( 877): #7 _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
E/flutter ( 877): #8 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
E/flutter ( 877): #9 Future._propagateToListeners (dart:async/future_impl.dart:711:32)
E/flutter ( 877): #10 Future._completeWithValue (dart:async/future_impl.dart:526:5)
E/flutter ( 877): #11 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36:15)
E/flutter ( 877): #12 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:298:13)
E/flutter ( 877): #13 Pages.getPage (package:spotify/src/endpoints/endpoint_paging.dart)
E/flutter ( 877):
E/flutter ( 877): #14 Pages.stream.handlePageAndGetNext
package:spotify/…/endpoints/endpoint_paging.dart:114
E/flutter ( 877): #15 _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter ( 877): #16 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter ( 877): #17 _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
E/flutter ( 877): #18 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
E/flutter ( 877): #19 Future._propagateToListeners (dart:async/future_impl.dart:711:32)
E/flutter ( 877): #20 Future._completeWithValue (dart:async/future_impl.dart:526:5)
E/flutter ( 877): #21 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36:15)
E/flutter ( 877): #22 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:298:13)

E/flutter ( 877): #23 Pages.getPage (package:spotify/src/endpoints/endpoint_paging.dart)
E/flutter ( 877):
E/flutter ( 877): #24 Pages.stream.handlePageAndGetNext
package:spotify/…/endpoints/endpoint_paging.dart:114
E/flutter ( 877): #25 _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter ( 877): #26 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter ( 877): #27 _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
E/flutter ( 877): #28 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
E/flutter ( 877): #29 Future._propagateToListeners (dart:async/future_impl.dart:711:32)
E/flutter ( 877): #30 Future._completeWithValue (dart:async/future_impl.dart:526:5)
E/flutter ( 877): #31 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36:15)
E/flutter ( 877): #32 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:298:13)
E/flutter ( 877): #33 Pages.getPage (package:spotify/src/endpoints/endpoint_paging.dart)
E/flutter ( 877):
E/flutter ( 877): #34 Pages.stream.handlePageAndGetNext
package:spotify/…/endpoints/endpoint_paging.dart:114
E/flutter ( 877): #35 _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter ( 877): #36 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter ( 877): #37 _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
E/flutter ( 877): #38 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
E/flutter ( 877): #39 Future._propagateToListeners (dart:async/future_impl.dart:711:32)
E/flutter ( 877): #40 Future._completeWithValue (dart:async/future_impl.dart:526:5)
E/flutter ( 877): #41 _AsyncAwaitCompleter.complete (dart:async-patch/async_patch.dart:36:15)
E/flutter ( 877): #42 _completeOnAsyncReturn (dart:async-patch/async_patch.dart:298:13)
E/flutter ( 877): #43 Pages.getPage (package:spotify/src/endpoints/endpoint_paging.dart)
E/flutter ( 877):
E/flutter ( 877): #44 Pages.stream.handlePageAndGetNext
package:spotify/…/endpoints/endpoint_paging.dart:114
E/flutter ( 877): #45 _rootRunUnary (dart:async/zone.dart:1192:38)
E/flutter ( 877): #46 _CustomZone.runUnary (dart:async/zone.dart:1085:19)
E/flutter ( 877): #47 _FutureListener.handleValue (dart:async/future_impl.dart:141:18)
E/flutter ( 877): #48 Future._propagateToListeners.handleValueCallback (dart:async/future_impl.dart:682:45)
E/flutter ( 877): #49 Future._propagateToListeners (dart:async/future_impl.dart:711:32)
E/flutter ( 877): #50 Future._completeWithValue
E/flutter ( 877): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: Error Code: 429
`
Seems like the error is from spotify itself but i don't understand why it occurs , since the spotify api is free and doesn't have limits for calls

How long can I leave open the api?

I've currently implemented some background services in my app and it needs to stay always open because for some devices (Xiaomi) the foreground service of android gets killed and even with START_STICKY may take some time to start or not start at all.

The issue that I'm facing is that if I leave the app open for more than 4/5 hours, I can open it from recent apps (first time) use it normally and then leave it in the background. If I do this again (second time) after 4/5 hours the app works again but if i close it and then re open it asks me to login.

Currently, my app at startup initialize a new SpotifyBase by providing the credentials obtained from the last login and save the new credentials obtained from the new login (especially the new refresh token) for the next login.
I do this because from my understanding the refresh token works only one time and when I get a successful login spotify's response contains a new refresh tocken to be used next time.

My supposition is that the API (spotify-dart) is refreshing the access token the first time but it's not saving the new refresh token for the second use.
Can this be the issue? Because I'm not sure..

Note: in all of this if the app is always open than the api works fine. When I close it and then open it after 12 hours of up time the refresh token is expired and it asks me to login

Can the search return Track instead of SimpleTrack?

Track class is actually the data structure that spotify returns yet this library returns the stripped down version SimpleTrack. I lose out on album information from the track when I search and get SimpleTrack. It makes more sense to return Track because you can still seamlessly cast this to a SimpleTrack if you don't require all of the info that Track provides. I'd rather not inherently lose information.

Thanks for your work :)

Unable to compile for Web

Hi! Thank you so much for this library!

I'm using Flutter 1.15.17 on the beta channel to build web apps. Once I do import 'package:spotify/spotify.dart', I'm introduced to a compiler error

Compiler message:
../../../../.pub-cache/hosted/pub.dartlang.org/spotify-0.3.0/lib/src/spotify_mock.dart:26:20: Error: Too few positional arguments: 2 required, 1 given.
    var file = File('test/data/$partialPath.json');
                   ^
Failed to compile application.

From delving into the code, I'm seeing that if the app is a web app the package imports dart:html, but the File constructor in html takes two arguments instead of the one given

factory File(List<Object> fileBits, String fileName, [Map options])

I could be doing something wrong, so any insight would be very helpful

Thank you again!

Currently Playing Not Working

var credentials = SpotifyApiCredentials(_clientId, _clientSecret);
var spotify = SpotifyApi(credentials);
var userplay = spotify.users.;
_now = await userplay.currentlyPlaying();

Giving error

How to grab user saved songs?

Curious on how to use the TracksMe endpoint to properly grab user saved songs to list similar to the example for Metallica.

Use in combination with SpotifySdk getAuthenticationToken

I'm trying to use this library in combination with https://github.com/brim-borium/spotify_sdk. SpotifySdk has a method to get a token from the spotify app but when I use it like this I get 401 when trying to access user data (my playlists in this case):

    FutureBuilder(
      future: SpotifySdk.getAuthenticationToken(
          clientId: '...',
          redirectUrl: 'comspotifytestsdk://callback',
          scope: scopes.join(', ')),
      builder: (context, snapshot) {
        if (snapshot.data == null) {
          return Scaffold(body: Center(child: Text('Not logged in')));
        }

        var credentials = SpotifyApiCredentials(
            '...',
            '...',
            accessToken: snapshot.data,
            scopes: scopes);

        /// ...
      },
    );

_$AlbumFromJson is not working when there is releaseDate

I see that the Album class is extending AlbumSimple and is overriding releaseDate and releaseDatePrecision without assigning the value to the superclass. The result of _$AlbumFromJson is so an Album with releaseDate and releaseDatePrecision equals null.
I suggest removing the override from the Album class.

Update library description

In this line say 'An incomplete library'
Maybe can update this to:

A dart library for interfacing with the Spotify API.

If this library is under construction, maybe indicate in README

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.