Spotify 网络播放器 API - 更改播放器请求

Spotify WebPlayer API - Change Player Request

我一直在使用 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)

我是不是漏something/formatting了?我尝试将 data 更改为 body,但我得到的是 400: Malformed JSON.

提前致谢!

我能够使用以下格式使其正常工作:

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)