You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Spotify API的albums/{id}/tracks端点获取50首以上曲目信息?

Fetching Tracks 51-120 from Spotify's albums/{id}/tracks Endpoint

No need to "bypass" anything—Spotify's API is built to handle this exact scenario with pagination parameters: limit and offset. Here's how to use them to grab tracks 51 through 120 using curl and jq:

Key Parameters Explained

  • limit: The maximum number of tracks returned per request (capped at 50, as you noted).
  • offset: The number of tracks to skip before starting the response. For example, offset=50 skips the first 50 tracks, so you’ll get tracks 51-100.

Step-by-Step Requests

  1. Get Tracks 51-100
    Use offset=50 and keep limit=50 (since this range fits exactly 50 tracks):

    curl -X GET "https://api.spotify.com/v1/albums/{YOUR_ALBUM_ID}/tracks?limit=50&offset=50" \
      -H "Authorization: Bearer YOUR_ACCESS_TOKEN" | \
      jq '.items[] | {track_name: .name, spotify_id: .id}'
    
  2. Get Tracks 101-120
    We only need 20 tracks here, so set limit=20 and offset=100 (skipping the first 100 tracks):

    curl -X GET "https://api.spotify.com/v1/albums/{YOUR_ALBUM_ID}/tracks?limit=20&offset=100" \
      -H "Authorization: Bearer YOUR_ACCESS_TOKEN" | \
      jq '.items[] | {track_name: .name, spotify_id: .id}'
    

Bonus: Automate Pagination for All Tracks Beyond 50

If you want to fetch all tracks after the first 50 (including 51-120) without manual requests, use a bash loop. First, grab the total number of tracks in the album, then iterate through offsets:

# Get total number of tracks in the album
TOTAL_TRACKS=$(curl -s -X GET "https://api.spotify.com/v1/albums/{YOUR_ALBUM_ID}/tracks?limit=1" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" | jq '.total')

# Start at offset 50 and loop until we've covered all tracks
OFFSET=50
while [ $OFFSET -lt $TOTAL_TRACKS ]; do
  # Calculate how many tracks to fetch in this request (max 50)
  LIMIT=$(( TOTAL_TRACKS - OFFSET > 50 ? 50 : TOTAL_TRACKS - OFFSET ))
  
  # Fetch and parse the tracks
  curl -s -X GET "https://api.spotify.com/v1/albums/{YOUR_ALBUM_ID}/tracks?limit=$LIMIT&offset=$OFFSET" \
    -H "Authorization: Bearer YOUR_ACCESS_TOKEN" | \
    jq '.items[] | {track_name: .name, spotify_id: .id}'
  
  # Move to the next offset
  OFFSET=$(( OFFSET + 50 ))
done

Just replace {YOUR_ALBUM_ID} and YOUR_ACCESS_TOKEN with your actual values, and this will output all tracks from 51 onwards, including the 101-120 range.

内容的提问来源于stack exchange,提问作者Hubert Léveillé Gauvin

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:03:28