【问题标题】:Spotify Web API giving me illegal scope no matter whatSpotify Web API 无论如何都会给我非法范围
【发布时间】:2021-09-10 07:11:57
【问题描述】:

我正在尝试在自己的 netlify 上建立一个开源 github 项目来分解它并从中学习。我在通过授权页面时遇到问题。无论我创建新的客户端 ID 多少次,我仍然会收到错误非法范围。据我所知,我所有的范围都是合法的,这就是让这变得更加混乱的原因。我已经删除了我的 spotify api 仪表板,现在重新制作了 3 次,但一点运气都没有。任何帮助或建议将不胜感激。我的仪表板上的重定向 URI 和客户端 ID 与我的代码中的相同(附在下面)。

const config = {
  environment: 'development',
  remoteUrl: 'https://api.spotify.com/v1/',
  spotifyAuthparams: {
    client_id: '***********************0b4de86f',
    redirect_uri: `${origin}/spotifycallback`,
    scope:
      'user-read-private user-top-read user-read-recently-played user-read-currently-playing playlist-modify-public playlist-modify-private playlist-read-collaborative user-read-play-history',
    show_dialog: true,
  },
};

export default config;

此代码显示 $(origin) 返回的内容。

const { protocol, hostname, port } = window.location;

const origin = `${protocol}//${hostname}${port ? `:${port}` : ''}`;

const config = {
  protocol,
  hostname,
  port,
  origin,
  spotifyAuthority: 'https://accounts.spotify.com/authorize',
};

export default config;

【问题讨论】:

    标签: javascript api scope spotify


    【解决方案1】:

    也许不是你的情况,但我也遇到了非法范围问题。我已使用此 URL 获取访问令牌:

    https://developer.spotify.com/console/get-playlists

    刚才我每次尝试都获得了非法范围。但是注销并再次登录解决了它(即使我第一次正确登录 - 我可以访问网络播放器没问题)。

    当我使用错误的 user_id 时,我也得到了非法范围 - 我使用另一个 user_id 登录,所以这并不奇怪,但我花了一段时间才弄明白。

    【讨论】:

      【解决方案2】:

      只需检查您的范围变量是否正确: 在此处从 Spotify 获取所有范围的列表: https://developer.spotify.com/documentation/general/guides/authorization/scopes/

      我就是这样解决的。自从我手动编写以来,几乎没有错别字。

      【讨论】:

        猜你喜欢
        • 2015-09-22
        • 2021-06-17
        • 2017-11-19
        • 1970-01-01
        • 2014-08-08
        • 2019-01-21
        • 2019-01-18
        • 2018-08-31
        • 1970-01-01
        相关资源
        最近更新 更多