brim-borium/spotify_sdk

Not able to get the authentication token

Closed this issue · 4 comments

The getAuthenticationToken is not working. It redirects me to spotify login and after login, it doesn't generate the access token and redirects me to the base route of my project which i am not even using.

Main.dart
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@OverRide
Widget build(BuildContext context) {
return MaterialApp(
initialRoute: HomePage.route,
debugShowCheckedModeBanner: false,
title: 'Spotify Music Recommender',
home: HomePage(),
routes: {
HomePage.route: (context) => HomePage(),
LoadingPage.route: (context) => LoadingPage(),
},
);
}
}

Home route:
static const String route = '/home';

Loading Screen route:
static const String route = '/loading';

getAuthenticationToken function:
Future getAuthenticationToken() async {
var authenticationToken = await SpotifySdk.getAuthenticationToken(
clientId: MyCLientID,
redirectUrl: 'http%3A%2F%2Flocalhost%3A61687%2F%23%2Floading',
scope: 'user-read-private,''user-read-email,''playlist-read-private,''playlist-read-collaborative,''user-library-read');
return authenticationToken;
}

I am calling it in the onPressed property of a raised button and I want to redirect to my loading screen which is the redirect url.
Instead my project redirects to localhost:61687/#/ even though my home route is localhost:61687/#/home (the route of my landing page).

Error:
┌───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
│ #0 C:/b/s/w/ir/cache/builder/src/out/host_debug/dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 906:28 get current
#1 packages/spotify_sdk/spotify_sdk.dart 548:15 logException
├┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
│ � getAuthenticationToken failed with: NoSuchMethodError: invalid member on null: 'length'
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
Error: PlatformException(error, NoSuchMethodError: invalid member on null: 'length', null, null)
at Object.throw
[as throw] (http://localhost:61687/dart_sdk.js:5347:11)
at StandardMethodCodec.decodeEnvelope (http://localhost:61687/packages/flutter/src/services/system_channels.dart.lib.js:797:19)
at MethodChannel._invokeMethod (http://localhost:61687/packages/flutter/src/services/system_channels.dart.lib.js:962:47)
at _invokeMethod.next ()
at http://localhost:61687/dart_sdk.js:39167:33
at _RootZone.runUnary (http://localhost:61687/dart_sdk.js:39024:58)
at _FutureListener.thenAwait.handleValue (http://localhost:61687/dart_sdk.js:34010:29)
at handleValueCallback (http://localhost:61687/dart_sdk.js:34570:49)
at Function._propagateToListeners (http://localhost:61687/dart_sdk.js:34608:17)
at _Future.new.[_completeWithValue] (http://localhost:61687/dart_sdk.js:34450:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:61687/dart_sdk.js:34473:35)
at Object._microtaskLoop (http://localhost:61687/dart_sdk.js:39311:13)
at _startMicrotaskLoop (http://localhost:61687/dart_sdk.js:39317:13)
at http://localhost:61687/dart_sdk.js:34824:9

I dont know why it isnt redirecting to the loading page and giving me the access token.
Please help, I am working with APIs for the first time on flutter.

@itsMatoosh any idea what could be the issue here?

@sanchman21 can you try running on Android? We have to see if this is a bug or a misconfiguration on your side.

@sanchman21 Did you make sure that the page at the redirect URL has the HTML contents as specified in the readme?

Closing this as stale. Feel free to comment if you are still facing the issue.