我正在使用 spotify_sdk 1.0.1 插件在我的 flutter 应用程序中发现身份验证。我已经设置了一切,当它处于调试模式但不在发布模式时也能正常工作。
请帮帮我。
pubspec.yaml-> 添加包
flutter_secure_storage:^3.3.5 url_launcher: ^5.7.10 spotify_sdk:^1.0.1
Future<void> connectToSpotifyRemote() async {
try {
setState(() {
_loading = true;
});
var result = await SpotifySdk.connectToSpotifyRemote(
clientId: clientId,
redirectUrl: redirectUrl,);
setStatus(result
? 'connect to spotify successful'
: 'connect to spotify failed');
setState(() {
_loading = false;
});
} on PlatformException catch (e) {
setState(() {
_loading = false;
});
setStatus(e.code, message: e.message);
} on MissingPluginException {
setState(() {
_loading = false;
});
setStatus('not implemented');
}
}
未来 getAuthenticationToken() 异步 { 试试{
var authenticationToken = await SpotifySdk.getAuthenticationToken(
clientId: clientId,
redirectUrl: redirectUrl,
scope: 'app-remote-control, '
'user-modify-playback-state, '
'playlist-read-private, '
'playlist-modify-public,user-read-currently-playing');
setStatus('Got a token: $authenticationToken');
return authenticationToken;
} on PlatformException catch (e) {
setStatus(e.code, message: e.message);
return Future.error('$e.code: $e.message');
} on MissingPluginException {
setStatus('not implemented');
return Future.error('not implemented');
}
}
void setStatus(String code, {String message = ''}) {
var text = message.isEmpty ? '' : ' : $message';
_logger.d('$code$text');
}
也在android模块中添加了包
spotify-auth spotify-app-remote
答案 0 :(得分:0)
确保您在 android manifest 文件夹中添加了互联网权限
<uses-permission android:name="android.permission.INTERNET" />