【问题标题】:Spotify WebPlayer API - Change Player RequestSpotify WebPlayer API - 更改播放器请求
【发布时间】:2021-02-01 14:52:29
【问题描述】:

我一直在使用 React 开发 Spotify 播放器,到目前为止,我已经能够让播放器正确连接到 API 并接收 device_id。

我的下一步是将播放器更改为新“制作”的播放器,但我继续收到400: Required field device_ids missing,即使我已将其包含在PUT 请求中:

const requestOptions = {
    method: 'PUT',
    headers: {
        'Authorization' : 'Bearer ' + spotifyAccessToken 
    }, 
    data: {
        "device_ids": [device_id],
        "play": 'true'
    }
};

// Change player
fetch('https://api.spotify.com/v1/me/player', requestOptions)

我是否遗漏了某些内容/格式不正确?我尝试将data 更改为body,但我得到了400: Malformed JSON

提前致谢!

【问题讨论】:

    标签: reactjs fetch jsx spotify


    【解决方案1】:

    我能够使用以下格式完成这项工作:

    const requestOptions = {
        method: 'PUT',
        body: JSON.stringify({
            device_ids: [southORadioDevId],
            play: 'true'
        }),
        headers: {
            Authorization: `Bearer ${spotifyAccessToken}`
        },
    };
    
    // Change player
    fetch('https://api.spotify.com/v1/me/player', requestOptions)
    

    【讨论】:

    • 非常感谢!我需要使用 JSON.stringify 来解决我的问题,这很有帮助!
    猜你喜欢
    • 2017-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-10
    • 1970-01-01
    • 2015-05-13
    • 1970-01-01
    • 2018-08-15
    相关资源
    最近更新 更多