You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Spotify API授权后跳转失败求助(自定义协议无处理程序)

Spotify授权接入应用后跳转错误调试求助

我正在尝试通过API将Spotify接入我的应用,前期流程正常,但授权完成后出现错误导致流程停滞。错误信息如下:

The resource was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it has an appropriate as value and it is preloaded intentionally.
login:1 Failed to launch 'com.lametric.developer.5ff35d10-429d-4454-8547-8b95d4b838a0://?code=AQC6nBxS9LddIe3Rbpd5_Zvkq26T2x5WIE0IWFKV_5e9ktQVMAjaaGgKac48OZwuSxwNt4s2F4pztQtWSdqaGaakzZGo3gbIfh8vLXxDdzbeiBuwoJHRzdM4wsGtMQ5kOQ1QKoX4LWAmVtIDrYN4xk6fMg9seiVOCHh2gO42pvgpJn2X3WK3s4XYXMV1E_5vnrwDWWHCduGlfG3-ADG0eDgC0Lx_Lzl4aSiG1b3dXEgkOQcM8RWfQpzIgKIPoKwK-yk#=' because the scheme does not have a registered handler.

以下是我的PHP代码:

// 替换为你自己的Spotify凭证
$clientId = 'xxxxx';
$clientSecret = 'xxxxx';

// Spotify授权URL
$authorizeUrl = 'https://accounts.spotify.com/authorize';

// 授权后的重定向URL
$redirectUri = "https://developer.lametric.com/redirect";

// Spotify获取令牌的URL
$tokenUrl = 'https://accounts.spotify.com/api/token';

// Spotify API基础URL
$apiBaseUrl = 'https://api.spotify.com/v1';

// 定义API所需的权限范围
$scope = 'user-read-currently-playing user-read-playback-state';

// 获取Spotify授权码
if (isset($_GET['code'])) {
  $code = $_GET['code'];

  // 用授权码交换Spotify访问令牌
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, $tokenUrl);
  curl_setopt($ch, CURLOPT_POST, 1);
  curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=authorization_code&code=' . $code . '&redirect_uri=' . $redirectUri);
  curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . base64_encode($clientId . ':' . $clientSecret)));
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  $tokenData = curl_exec($ch);
  curl_close($ch);

  // 将访问令牌存储到会话中
  session_start();
  $_SESSION['access_token'] = json_decode($tokenData)->access_token;
}


// 检查用户是否已授权
if (!isset($_SESSION['access_token'])) {

  // 重定向用户到Spotify授权页面
  $authorizeParams = array(
    'client_id' => $clientId,
    'response_type' => 'code',
    'redirect_uri' => 'https://developer.lametric.com/redirect',
    'scope' => $scope,
  );
    $url=http_build_query($authorizeParams);
    $url2=rawurldecode($url);
    header("location:". $authorizeUrl . '?' . $url2);
    //die();

}

我已经在Spotify开发者后台正确注册了重定向URI,请求协助调试该问题。(附相关配置截图)


内容的提问来源于stack exchange,提问作者Pierre-Marie

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.23 13:47:47