[英]Spotify API Post Request Add Tracks To Playlist - ERROR 400 BAD REQUEST
我在使用Spotify API將曲目添加到用戶播放列表時遇到了一個非常常見的錯誤。 在以前的提取方法中,我已經獲得了用戶playlistId,現在正嘗試使用該playlistId將曲目發布到該播放列表上。 我遵循了文檔,但顯然缺少一些內容,這是代碼:
` //userUd, playlistId, currentUserAccessToken, trackURIs are all defined
fetch(`https://api.spotify.com/v1/users/${userId}/playlists/${playlistId}/tracks`, {
headers: {
'Authorization': 'Bearer ' + currentUserAccessToken
},
contentType: 'application/json',
method: 'POST',
body: JSON.stringify({
"uris": `[${trackURIs}]`
})
}).then(success => {
return success;
}).catch(err => {
console.log('here is your error', err);
})`
我執行了GET請求來授權用戶-包括創建公共播放列表的范圍,在可以正常工作的其他代碼塊中,這是:
`let scopes ='playlist-modify-public';
window.location.replace( https://accounts.spotify.com/authorize?client_id=${clientID}&scope=${scopes}&redirect_uri=${redirectURI}&response_type=token
{ https://accounts.spotify.com/authorize?client_id=${clientID}&scope=${scopes}&redirect_uri=${redirectURI}&response_type=token
} https://accounts.spotify.com/authorize?client_id=${clientID}&scope=${scopes}&redirect_uri=${redirectURI}&response_type=token
scope https://accounts.spotify.com/authorize?client_id=${clientID}&scope=${scopes}&redirect_uri=${redirectURI}&response_type=token
${ https://accounts.spotify.com/authorize?client_id=${clientID}&scope=${scopes}&redirect_uri=${redirectURI}&response_type=token
} https://accounts.spotify.com/authorize?client_id=${clientID}&scope=${scopes}&redirect_uri=${redirectURI}&response_type=token
redirect_uri https://accounts.spotify.com/authorize?client_id=${clientID}&scope=${scopes}&redirect_uri=${redirectURI}&response_type=token
${ https://accounts.spotify.com/authorize?client_id=${clientID}&scope=${scopes}&redirect_uri=${redirectURI}&response_type=token
} https://accounts.spotify.com/authorize?client_id=${clientID}&scope=${scopes}&redirect_uri=${redirectURI}&response_type=token
response_type https://accounts.spotify.com/authorize?client_id=${clientID}&scope=${scopes}&redirect_uri=${redirectURI}&response_type=token
token);`
萬分感謝!
JSON數組中的每個元素都需要用引號引起來。 因此,應引用每條音軌,如下所示:
{"uris": ["spotify:track:4iV5W9uYEdYUVa79Axb7Rh", "spotify:track:1301WleyT98MSxVHPZCA6M"]}
我認為您提供的對象名稱uris具有無效的數組。
並且,請注意,您也可以將播放列表項作為查詢參數傳遞(而不是在正文中),而無需使用json。 https://developer.spotify.com/web-api/add-tracks-to-playlist/
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.