Logo
Section 1 / 3

保存与移除收藏歌曲

学习如何使用 Spotify API 管理用户资料中的播放列表。

导入

保存与移除收藏歌曲

学习如何使用 Spotify API 管理用户资料中的播放列表。

查询参数类别类型描述
ids必需字符串包含我们想要保存到当前用户资料中的歌曲 ID。这些 ID 用逗号(,)分隔。一次调用最多可保存 50 首歌曲。

查询参数类别类型描述
ids必需字符串包含我们想要从当前用户资料中删除的歌曲 ID。这些 ID 用逗号(,)分隔。一次调用最多可删除 50 首歌曲。
1const endpointUrl = new URL('https://api.spotify.com/v1/me/tracks'); 2 3const queryParameters = new URLSearchParams({ 4 ids: '4rHZZAmHpZrA3iH5zx8frV,3C0nOe05EIt1390bVABLyN' 5 //4rHZZAmHpZrA3iH5zx8frV 是歌曲《Mirrors》的 Spotify ID 6 //3C0nOe05EIt1390bVABLyN 是歌曲《On the Floor》的 Spotify ID 7}); 8 9headerParameters = { 10 'Content-Type': 'application/json', 11 'Authorization': 'Bearer {{AUTHORIZATION_CODE_ACCESS_TOKEN}}' 12} 13 14const options = { 15 method: 'PUT', 16 headers: headerParameters 17}; 18 19async function saveTrack() { 20 try { 21 endpointUrl.search = queryParameters; 22 const response = await fetch(endpointUrl, options); 23 printResponse(response); 24 } catch (error) { 25 printError(error); 26 } 27} 28 29saveTrack();
1const endpointUrl = new URL('https://api.spotify.com/v1/me/tracks'); 2 3const queryParameters = new URLSearchParams({ 4 ids: '3C0nOe05EIt1390bVABLyN' 5 //3C0nOe05EIt1390bVABLyN 是歌曲《On the Floor》的 Spotify ID 6}); 7 8headerParameters = { 9 'Content-Type': 'application/json', 10 'Authorization': 'Bearer {{AUTHORIZATION_CODE_ACCESS_TOKEN}}' 11} 12 13const options = { 14 method: 'DELETE', 15 headers: headerParameters 16}; 17 18async function removeTrack() { 19 try { 20 endpointUrl.search = queryParameters; 21 const response = await fetch(endpointUrl, options); 22 printResponse(response); 23 } catch (error) { 24 printError(error); 25 } 26} 27 28removeTrack();

播放列表

用户收藏的歌曲及歌曲信息