未处理的异常:在 Flutter 应用程序中调用 Spotify 授权时出现 PlatformException

问题描述 投票:0回答:1

我正在尝试制作一个简单的 Flutter 应用程序,让用户登录 Spotify 并聚合收听活动、显示统计信息等。

我在使用 Spotify API 时遇到一些问题。每次我尝试启动 Spotify 授权 URL 时,我都会从 Flutter 收到以下错误消息。

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(Error, Error while launching https://accounts.spotify.com/authorize/?response_type=code&client_id=6b12ed8ef79648e88e6646d7f16f5a50&scope=user-read-private&redirect_uri=http://localhost:8888//callback, null, null)

这是我获取 URL 的代码。

Future<void> login(BuildContext context) async {
    await dotenv.load();

    final clientId = dotenv.env['SPOTIFY_CLIENT_ID'];
    final scopes = dotenv.env['SPOTIFY_SCOPES'];
    final redirectUri = dotenv.env['SPOTIFY_REDIRECT_URI'];
    final url = Uri.parse('https://accounts.spotify.com/authorize/'
        '?response_type=code'
        '&client_id=$clientId'
        '&scope=$scopes'
        '&redirect_uri=$redirectUri');

    // Launch the constructed URL using url_launcher
    await launchUrl(url);
  }

我的环境变量在哪里

SPOTIFY_CLIENT_ID=6b12ed8ef79648e88e6646d7f16f5a50
SPOTIFY_SECRET_ID=...
SPOTIFY_REDIRECT_URI=http://localhost:8888//callback
SPOTIFY_SCOPES=user-read-private

(旁注:可以分享我的客户端 ID 吗?我已经删除了我的秘密 ID)

我已经搞乱了重定向 URI,但没有成功。我已经仔细检查过我的重定向 URI 是否与我的 Spotify 开发者平台相同。

最终目标是成功登录,获取用户访问令牌,然后导航出Web授权页面。

提前感谢您的帮助。

ios flutter oauth authorization spotify
1个回答
0
投票

您是否尝试卸载应用程序并运行 flutter clean ? 也许可以解决问题。

© www.soinside.com 2019 - 2024. All rights reserved.