导入
艺术家信息
使用艺术家的 Spotify ID 搜索有关该艺术家的信息。
获取艺术家 端点用于通过艺术家的 Spotify ID 获取有关该艺术家的信息。此端点的基础 URL 为 https://api.spotify.com/v1/artists/{id}。路径参数 {id} 将被替换为所需信息的艺术家 ID。假设我们想要获取 Spotify ID 为 sample_id 的艺术家的详细信息,此时的 URL 将为 https://api.spotify.com/v1/artists/sample_id。
1const endpointUrl = new URL('https://api.spotify.com/v1/artists/0TnOYISbd1XYRBk9myaseg'); 2// 0TnOYISbd1XYRBk9myaseg 是 Pitbull 的 ID 3 4headerParameters = { 5 'Content-Type': 'application/json', 6 'Authorization': 'Bearer {{CLIENT_CREDENTIALS_ACCESS_TOKEN}}' 7} 8 9const options = { 10 method: 'GET', 11 headers: headerParameters 12}; 13 14async function fetchArtistInformation() { 15 try { 16 const response = await fetch(endpointUrl, options); 17 18 printResponse(response); 19 } 20 catch (error) { 21 printError(error); 22 } 23} 24 25fetchArtistInformation();
| 艺术家姓名 | Spotify ID |
|---|---|
| 基思·哈林 | 3HyxTmsgPkff0qbmLxiaJz |
| Eminem | 7dGJo4pcD2V6oG8kP0tJRR |
| Beyoncé | 6vWDO969PvNqNYHIOW5v0m |
| Imagine Dragons | 53XhwfbYqKCa1cC15pYq2q |
| 约翰尼·卡什 | 6kACVPfCOnqzgfEF5ryl0x |
| 响应字段 | 类型 | 描述 |
|---|---|---|
| spotify | 字符串 | 艺术家在 Spotify 上的页面链接。 |
| followers | 对象 | 包含艺术家关注者信息的对象。包含两个元素:href(始终为 NULL)和 total(表示关注者数量)。 |
| genres | 字符串数组 | 艺术家参与过的音乐流派列表。 |
| href | 字符串 | 指向提供艺术家完整详情的端点链接。 |
| id | 字符串 | 艺术家的 Spotify ID。 |
| images | 对象数组 | 包含艺术家图像信息的数组。每个对象包含三个元素:图像的 URL、高度和宽度。 |
| name | 字符串 | 艺术家的名称。 |
| popularity | 整数 | 基于艺术家歌曲受欢迎程度计算的流行度评分,范围为 0 到 100,100 为最热门。 |
| 参数 | 分类 | 类型 | 描述 |
|---|---|---|---|
| ids | 必需 | 字符串 | 以逗号分隔的艺术家 Spotify ID 列表,用于获取其详细信息。 |
1const endpointUrl = new URL('https://api.spotify.com/v1/artists'); 2 3const queryParameters = new URLSearchParams({ 4 ids: '2CIMQHirSU0MQqyYHq0eOx,57dN52uHvrHOxijzpIgu3E,1vCWHaC5f2uS3yhpwWbIA6' 5}); 6// 2CIMQHirSU0MQqyYHq0eOx 是 deadmau5 的 ID 7// 57dN52uHvrHOxijzpIgu3E 是 Ratatat 的 ID 8// 1vCWHaC5f2uS3yhpwWbIA6 是 Avicii 的 ID 9 10headerParameters = { 11 'Content-Type': 'application/json', 12 'Authorization': 'Bearer {{CLIENT_CREDENTIALS_ACCESS_TOKEN}}' 13} 14 15const options = { 16 method: 'GET', 17 headers: headerParameters 18}; 19 20async function fetchArtistsDetails() { 21 try { 22 endpointUrl.search = queryParameters; 23 const response = await fetch(endpointUrl, options); 24 25 printResponse(response); 26 } 27 catch (error) { 28 printError(error); 29 } 30} 31 32fetchArtistsDetails();