C
C#14mo ago
PotatoNeto

✅ Help with SpotifyAPI

I'm trying to retrieve more than a 100 songs at once from a playlist in Spotify and I can't get it to work. And I have no idea how to make that work. No need to send code since I didn't start to write anything, ChatGPT suggested a few things but non of them worked. Please help :) Thanks in advance.
33 Replies
Pobiega
Pobiega14mo ago
How are we supposed to help given the information you provided so far? We don't provide support for the Spotify API
Jimmacle
Jimmacle14mo ago
if i had to guess that's probably an intentional limitation of their API their documentation should provide that information
Pobiega
Pobiega14mo ago
The search endpoint explicitly states its limits
PotatoNeto
PotatoNetoOP14mo ago
What else would want me to give you? I couldn't find it I also couldn't find a Discord server that provides such thing, so it makes sense to send it in the C# server. Someone PROBABLY used the SpotifyAPI in here.
Pobiega
Pobiega14mo ago
If you literally Google "Spotify API search" it's the first hit lol
PotatoNeto
PotatoNetoOP14mo ago
Let me rephrase my problem Fixed it
Anu6is
Anu6is14mo ago
you have to make multiple requests
PotatoNeto
PotatoNetoOP14mo ago
Oof, isn't there a way to do it without multiple requests?
Jimmacle
Jimmacle14mo ago
what does their documentation say
PotatoNeto
PotatoNetoOP14mo ago
try{
var playlist = await spotify.Playlists.Get(playlistID);

if((playlist.Tracks == null) || (playlist.Tracks.Items == null) || (playlist.Tracks.Items.Count <= 0)) {
throw new Exception("No songs in playlist.");
}

playlist.Tracks.Limit = 350; // THIS LINE

return playlist.Tracks.Items;
}
catch(Exception e) {
System.Console.WriteLine(e.Message);
System.Console.WriteLine();

return new List<PlaylistTrack<IPlayableItem>>();
}
try{
var playlist = await spotify.Playlists.Get(playlistID);

if((playlist.Tracks == null) || (playlist.Tracks.Items == null) || (playlist.Tracks.Items.Count <= 0)) {
throw new Exception("No songs in playlist.");
}

playlist.Tracks.Limit = 350; // THIS LINE

return playlist.Tracks.Items;
}
catch(Exception e) {
System.Console.WriteLine(e.Message);
System.Console.WriteLine();

return new List<PlaylistTrack<IPlayableItem>>();
}
I added this line and it still returns a list with 100 and that's it. I took this line from their docs.
Jimmacle
Jimmacle14mo ago
so you're fetching something from their API, modifying the response, and expecting that to change the request that you already sent? i'm confused
Pobiega
Pobiega14mo ago
Uhm.. You do understand that you are setting the value on it, after it has already been fetched
PotatoNeto
PotatoNetoOP14mo ago
Yea I got that. And just 1 thing, instead of pointing out my errors, why won't you help me? Clearly I don't know very well what I'm doing, right? So help me. Don't be like that.
Jimmacle
Jimmacle14mo ago
we're helping you right now?
Pobiega
Pobiega14mo ago
If by "help" you mean "give me the code", thats not happening.
PotatoNeto
PotatoNetoOP14mo ago
That's not I meant.
Jimmacle
Jimmacle14mo ago
if that doesn't involve telling you what you're doing wrong, what is "helping" supposed to look like if you're looking for someone to just hand you an answer, that's not how we do things here
Pobiega
Pobiega14mo ago
If you don't understand something, ask about it. But try to ask specific questions. Based on the above, it looks like you want to fetch the tracks of a given playlist. The API documentation for that is https://developer.spotify.com/documentation/web-api/reference/get-playlists-tracks look at the API doc page, specifically where it says "limit" and tell us what it says
PotatoNeto
PotatoNetoOP14mo ago
Ok. I saw that, though you see at the top it's says playlists/{playlistId}/tracks?
Pobiega
Pobiega14mo ago
yep, thats the API path
PotatoNeto
PotatoNetoOP14mo ago
Right, but in my code, in that certain (and only) line I see the Playlists(id) I don't quite understand where I should put the #Tracks.
Jimmacle
Jimmacle14mo ago
do you have documentation for the C# API wrapper you're using?
PotatoNeto
PotatoNetoOP14mo ago
I found this (right when I started working with that api) but I can't find what I need here. https://johnnycrazy.github.io/SpotifyAPI-NET/
SpotifyAPI-NET | SpotifyAPI-NET
Documentation for the C# .NET SpotifyAPI-NET Library
Jimmacle
Jimmacle14mo ago
there is an overload for that method that takes an object with additional options that should let you do what you want, if not then you'll need to find a wrapper that exposes the parts of the API you need but you still won't get more than 100 items at once, in fact i'm surprised you're getting that since spotify's documentation says the limit is 50 the API is what's called paginated, if you want more data you have to manipulate the offset and limit options to get it in multiple parts
Pobiega
Pobiega14mo ago
the wrapper you are using seems to be doing some of that work for you https://johnnycrazy.github.io/SpotifyAPI-NET/docs/pagination
PotatoNeto
PotatoNetoOP14mo ago
What's paginate? ok nvm it's says it right here
Pobiega
Pobiega14mo ago
so instead of just accessing Items directly, you're expected to use the Paginate and PaginateAll methods on the playlist.Tracks So to answer this, it would have been very useful to link to the Spotify API wrapper you were using in your original post. You didn't say anything about a wrapper, so I assumed you were using the API directly
PotatoNeto
PotatoNetoOP14mo ago
Ok, now I know that. Thanks Pobiega
Pobiega
Pobiega14mo ago
the more information you provide, the better help you get
PotatoNeto
PotatoNetoOP14mo ago
Yea, I just never thought about sending the wrapper link Just saying it worked, thanks a lot and sorry if I wasn't clear at the beginning.
Pobiega
Pobiega14mo ago
No worries, glad you got it working and hopefully learned how to better ask questions for next time 🙂 consider $close -ing this thread
MODiX
MODiX14mo ago
Use the /close command to mark a forum thread as answered
Want results from more Discord servers?
Add your server