Spotify 网络播放器 SDK。身份验证错误:令牌范围无效

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

我尝试使用 Web Playback SDK 在我自己的应用程序中播放歌曲。 在 OAuth 回调响应中我得到了这个:

credentials = {AuthorizationCodeCredentials@9873}“AuthorizationCodeCredentials(accessToken = BQBfqJ8wnZUKg,tokenType = Bearer,范围=播放列表读取私有流用户修改播放状态用户读取播放状态用户当前读取-播放用户最近播放过的内容, expiresIn=3600,refreshToken=AQCfiBnh4)" accessToken =“BQBfqJ8wnZUKg” tokenType = "承载者" 范围=“播放列表读取专用流用户修改播放状态用户读取播放状态用户读取当前播放用户读取最近播放用户读取电子邮件” 过期= {Integer@11904} 3600 刷新令牌=“AQCfiBnh4”

这表示我获得了一个令牌,提供了我需要播放的所有范围。

当我在播放器中使用令牌时,我在浏览器开发模式下收到消息:

player.component.ts:68 传递给 SDK 的令牌:BQBfqJ8***wnZUKg 索引.js:3 GET https://api.spotify.com/v1/melody/v1/check_scope?scope=web-playback 403(禁止) player.component.ts:103 身份验证错误:令牌范围无效。 player.component.ts:88 Web Playback SDK 成功连接 Spotify!

这是一个错误,我得到了无效的令牌范围吗?

代码片段如下所示:

/**
 * Initializes the Spotify Web Playback SDK player instance.
 */
initSpotifyPlayer() {
  console.log('Initializing Spotify Player...');
  this.player = new window.Spotify.Player({
    name: 'Your Web Player',
    getOAuthToken: async (cb: (token: string) => void) => {
      try {
        const token = this.spotifyService.getToken(); // Fetch token
        if (token) {
          console.log('Token passed to SDK:', token);
          cb(token); // Pass token to SDK
        } else {
          console.error('No valid token found');
          cb(''); // Pass empty string to avoid errors
        }
      } catch (error) {
        console.error('Error fetching token:', error);
        cb(''); // Pass empty string in case of error
      }
    },
    volume: 0.5
  });

  // Set up event listeners for the player
  this.setupPlayerListeners();

  // Connect to Spotify
  this.player.connect().then((success: boolean) => {
    if (success) {
      console.log('The Web Playback SDK successfully connected to Spotify!');
    } else {
      console.error('Failed to connect to Spotify');
    }
  });
}

/**
 * Sets up event listeners for Spotify Web Playback SDK player events.
 */
setupPlayerListeners() {
  this.player.addListener('initialization_error', (error: ErrorMessage) => {
    console.error('Initialization error:', error.message);
  });
  this.player.addListener('authentication_error', (error: ErrorMessage) => {
    console.error('Authentication error:', error.message);
  });
  this.player.addListener('account_error', (error: ErrorMessage) => {
    console.error('Account error:', error.message);
  });
  this.player.addListener('playback_error', (error: ErrorMessage) => {
    console.error('Playback error:', error.message);
  });
  this.player.addListener('player_state_changed', (state: PlayerState) => {
    console.log('Player state changed:', state);
  });
}

有人面临同样的问题吗?

干杯 斯特凡

sdk spotify
1个回答
0
投票

发现错误:user-read-private 范围缺失。

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