getAccessToken static method
Returns an access token as a String
Required parameters are the clientId
and the redirectUrl
to
authenticate with the Spotify Api.
Also you have to provide a scope
like
"app-remote-control, user-modify-playback-state, playlist-read-private,
playlist-modify-public,user-read-currently-playing"
See https://developer.spotify.com/documentation/general/guides/scopes/
for more scopes and how to use them
The token can be used to communicate with the web api
iOS specific: You can optionally pass a spotifyUri
. A blank string will play the user's last song or pick a random one. It will be ignored on platforms other than iOS.
Throws a PlatformException if retrieving the access token
failed.
Throws a MissingPluginException if the method is not implemented on
the native platforms.
Implementation
static Future<String> getAccessToken(
{required String clientId,
required String redirectUrl,
String spotifyUri = '',
bool asRadio = false,
String? scope}) async {
try {
final authorization =
await _channel.invokeMethod(MethodNames.getAccessToken, {
ParamNames.clientId: clientId,
ParamNames.redirectUrl: redirectUrl,
ParamNames.scope: scope,
ParamNames.spotifyUri: spotifyUri,
ParamNames.asRadio: asRadio,
});
return authorization.toString();
} on Exception catch (e) {
_logException(MethodNames.getAccessToken, e);
rethrow;
}
}