Post

Replies

Boosts

Views

Activity

Reply to Apple Music API fetch more than 10 recently played songs
Hey @swiftymoon, I have the same issue. I was looking to get recently-played tracks from Apple Music. I used Spotify before, which returns up to 50 recently played tracks, so was disappointed with Apple Music API. I look a bit deeper into this. TL;DR: This endpoint supports offset, so you can reach resources beyond the 10 resources limit by setting the right offset. Update 1: The endpoint yields at most 50 most recently played resources. So with the limit of 10, using offset values 0, 10, 20, 30, and 40 will give you all recently played resources you can access. Observation 1: If you set limit above 10, you get an error in the payload. This confirms we have to operate in the range of 1-10 resources per request. json { "errors": [ { "id": "X6VOUROLIVE5XJSVKIA5FFHQEI", "title": "Invalid Parameter Value", "detail": "Value must be an integer less than or equal to 10", "status": "400", "code": "40005", "source": { "parameter": "limit" } } ] } Just out of curiosity, limit that's less than 1 (so 0 and including negatives) also throws. Observation 2: offset DOES work for this endpoint Other endpoints accept offset query param, so I tried I here too. Good news, offset works! Endpoints and results I've got: I had just 4 entries in recently played. That was expected, today was the first time I've used Apple Music. https://api.music.apple.com/v1/me/recent/played recently-played-all.json - https://developer.apple.com/forums/content/attachment/75710724-aec5-44ac-8de5-0796b8519116 When I set the limit=2, I got just 2 entries. As expected. https://api.music.apple.com/v1/me/recent/played?limit=2 recently-played-limit-2.json - https://developer.apple.com/forums/content/attachment/42526391-fd32-45f9-bad5-853f7c7f025d Then I tried to get "next page", so limit=2&offset=2. And lo and behold, I got the next page! https://api.music.apple.com/v1/me/recent/played?limit=2&offset=2 recently-played-limit-2-offset-2.json - https://developer.apple.com/forums/content/attachment/a32e187d-cc3a-4c3e-a025-0d83da857d61 Then I also looked at what happens if you set offset beyond what's in the recently-played list. As expected, I got empty array. https://api.music.apple.com/v1/me/recent/played?offset=10 recently-played-offset-10.json - https://developer.apple.com/forums/content/attachment/fb8a8fd5-d8cb-4b6f-a960-8ce6e3413f47 The offset can be set to as high as 1000000000s (10^9). At 10000000000 (one more zero), the query param is ignored. Negative offset is ignored. Conclusion: You can only get between 1-10 recently-played resources. You can use offset to get resources beyond the 10 items limit. The question remains about how many recently-played resources are made available in total. E.g. Spotify keeps only the last 50 tracks. Anything older than that and you're out of luck. How many are available via Apple Music API? See Update 1 - you can get max 50 recently played resources. Docs at the time of writing: Apple Music API Docs: https://developer.apple.com/documentation/applemusicapi/get_recently_played_resources Spotify API Docs: https://developer dot spotify dot com/documentation/web-api/reference/#endpoint-get-the-users-currently-playing-track
Mar ’21
Reply to Apple Music API > Fetch Recent > Can I get songs?
Hey @Dott, 3 yrs later and I'm on the same boat as you. The endpoint for recently played returns only albums, playlists, and stations. But still no songs. I tried playing song individually, and via "play next", but the individual tracks are not reflected in the endpoint's result. This compares poorly against Spotify's API, which give you up to 50 most-recently played tracks. Apple Music API Docs: https://developer.apple.com/documentation/applemusicapi/get_recently_played_resources Spotify API Docs: https://developer dot spotify dot com/documentation/web-api/reference/#endpoint-get-the-users-currently-playing-track
Mar ’21