Logo
Section 1 / 2

搜索 Spotify 资源

学习如何搜索关于艺术家、播放列表、专辑、节目或剧集的信息。

导入

搜索 Spotify 资源

学习如何搜索关于艺术家、播放列表、专辑、节目或剧集的信息。

搜索端点允许我们搜索任何艺术家、专辑、歌曲、播客或节目相关信息。该端点的基础URI为 https://api.spotify.com/v1/search,返回Spotify上可获取的信息。此端点提供可用于其他需要Spotify ID的端点的Spotify ID。

查询参数类别类型描述
q必需字符串要通过此端点搜索的查询关键词。
type必需字符串要搜索的类别。可能的选项包括:album(专辑)、artist(艺术家)、playlist(播放列表)、track(歌曲)、show(节目)、episode(单集)。也可以通过逗号(,)分隔多个类别。
include_external可选字符串决定用户是否可以播放外部托管的音频。该参数唯一可能的值是 audio,表示允许用户播放外部托管的音频。默认情况下,用户不允许这样做。
limit可选整数限制响应中返回的项目数量。取值范围为0到50,默认值为20。
market可选字符串用于获取特定国家内容的ISO 3166-1 alpha-2国家代码。例如,us代表美国,es代表西班牙,fr代表法国。如果在请求头中发送了授权码访问令牌,则用户的国家将优先于本参数指定的国家。
offset可选整数用于偏移响应中的第一个项目。
1const endpointUrl = new URL('https://api.spotify.com/v1/search'); 2 3const queryParameters = new URLSearchParams({ 4 q: 'metallica', 5 type: 'artist' 6}); 7headerParameters = { 8 'Content-Type': 'application/json', 9 'Authorization': 'Bearer {{CLIENT_CREDENTIALS_ACCESS_TOKEN}}' 10} 11 12const options = { 13 method: 'GET', 14 headers: headerParameters 15}; 16 17async function searchArtist() { 18 try { 19 endpointUrl.search = queryParameters; 20 const response = await fetch(endpointUrl, options); 21 22 printResponse(response); 23 } 24 catch (error) { 25 printError(error); 26 } 27} 28 29searchArtist();
1const endpointUrl = new URL('https://api.spotify.com/v1/search'); 2 3const queryParameters = new URLSearchParams({ 4 q: 'metallica', 5 type: 'artist' 6}); 7headerParameters = { 8 'Content-Type': 'application/json', 9 'Authorization': 'Bearer {{AUTHORIZATION_CODE_ACCESS_TOKEN}}' 10} 11 12const options = { 13 method: 'GET', 14 headers: headerParameters 15}; 16 17async function searchArtistWithUserToken() { 18 try { 19 endpointUrl.search = queryParameters; 20 const response = await fetch(endpointUrl, options); 21 22 printResponse(response); 23 } 24 catch (error) { 25 printError(error); 26 } 27} 28 29searchArtistWithUserToken();
响应字段类型描述
genres字符串数组包含该艺术家参与过的音乐流派的数组。
name字符串艺术家的名称。
popularity整数表示艺术家在Spotify上的受欢迎程度,范围从0到100,100为最热门。
images对象 [数组]包含艺术家图像信息。数组中的每个对象包含三个元素,分别提供图像的URL、高度和宽度。
id字符串艺术家的Spotify ID。
next字符串下一页的链接。
previous字符串上一页的链接。
total整数与本次查询匹配的项目总数(此例中为艺术家总数)。

简介

最新发布