GBruce82 / Jammming

Jammming Project - Codecademy
0 stars 0 forks source link

Spotify.search #15

Open mp1pro opened 6 years ago

mp1pro commented 6 years ago

The search api can tightened up a bit, only a couple out of place return syntax was changed. Here is the code:

  search(term) {
    const accessToken = Spotify.getAccessToken();
    return fetch(`https://api.spotify.com/v1/search?type=track&q=${term}`, {
      headers: {
        Authorization: `Bearer ${accessToken}`
      }
    }).then(response => {
      return response.json();
    }).then(jsonResponse => {
      if (!jsonResponse.tracks) {
        return [];
      }
      return jsonResponse.tracks.items.map(track => ({
        id: track.id,
        name: track.name,
        artist: track.artists[0].name,
        album: track.album.name,
        uri: track.uri
      }));
    });
},
GBruce82 commented 6 years ago

Marvin,

Please look at my search api again on Github. It's up to date now and I can adjust how many results I get up to 50. I tried to get more than 50 but the app refuses to search with more than 50. I've tried to figure out how to get more than 50 in the css files but I can't find it. Is that a limitation in Spotify and I've been looking in the wrong place? It's not limited in the css it's limited by Spotify?

Greg


From: Marvin Parke notifications@github.com Sent: Wednesday, January 10, 2018 2:59:24 AM To: GBruce82/Jammming Cc: Subscribed Subject: [GBruce82/Jammming] Spotify.search (#15)

The search api can tightened up a bit, only a couple out of place return syntax was changed. Here is the code:

search(term) { const accessToken = Spotify.getAccessToken(); return fetch(https://api.spotify.com/v1/search?type=track&q=${term}, { headers: { Authorization: Bearer ${accessToken} } }).then(response => { return response.json(); }).then(jsonResponse => { if (!jsonResponse.tracks) { return []; } return jsonResponse.tracks.items.map(track => ({ id: track.id, name: track.name, artist: track.artists[0].name, album: track.album.name, uri: track.uri })); }); },

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/GBruce82/Jammming/issues/15, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AfJjZzfyZx7rXD_JDIjmJxhXMmufKtkpks5tJJgMgaJpZM4RZJIv.

mp1pro commented 6 years ago

50 appears to be the max. This can be adjusted for some endpoints by using the limit parameter like so https://api.spotify.com/v1/users/yyy/playlists/xxx/tracks?offset=0&limit=50&market=from_token.

GBruce82 commented 6 years ago

So it is a Spotify limitation and I was looking in the wrong place. Thanks for the link. I’ll go out there today and learn something new! That’s a GOOD thing.

Thank you for all your help, Marvin!!

Greg & Lynn

On Jan 11, 2018, at 5:40 AM, Marvin Parke notifications@github.com<mailto:notifications@github.com> wrote:

50 appears to be the max. This can be adjusted for some endpoints by using the limit parameter like so https://api.spotify.com/v1/users/yyy/playlists/xxx/tracks?offset=0&limit=50&market=from_token.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/GBruce82/Jammming/issues/15#issuecomment-356936637, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AfJjZzER8KSQvEvsjnjfo-Wx51x2J8QBks5tJg88gaJpZM4RZJIv.