1

I've looked into how to play 30 second previews but so far all I can find is android wrappers for the web API that require user authentication.

I need to be able to search for an artist and play the first preview that pops up without needing the user to authenticate their accounts

MichaelStoddart
  • 5,571
  • 4
  • 27
  • 49

3 Answers3

1

You should check: https://developer.spotify.com/web-api/code-examples/

"Search for an Artist (and Lookup) Demo"

It's an example for a web snippet, but you could try to see how it does the connection without needing the user authentication.

Arnold.M
  • 23
  • 3
0

If you look at spotify api webpage they mention Endpoints marked “OAuth” above require application registration and user authorization via the Spotify Accounts Service to access certain data.

To Kra
  • 3,344
  • 3
  • 38
  • 45
0

So in order to get this working i had to chain 2 API calls together. The first one searches for the artist and then the second one looks for the preview:

You call the API with this link (GET): https://api.spotify.com/v1/search?q=<artist name>&type=artist

which then returns a json structure like this:

{
    "artists": {
    "href": "https://api.spotify.com/v1/search?query=bring+me+the+horizon&offset=0&limit=20&type=artist",
    "items": [
    {
    "external_urls": {
    "spotify": "https://open.spotify.com/artist/1Ffb6ejR6Fe5IamqA5oRUF"
    },
    "followers": {
    "href": null,
    "total": 1067846
    },
    "genres": [
    "metalcore"
    ],
    "href": "https://api.spotify.com/v1/artists/1Ffb6ejR6Fe5IamqA5oRUF",
    "id": "1Ffb6ejR6Fe5IamqA5oRUF",
    "images": [
    {
    "height": 640,
    "url": "https://i.scdn.co/image/49aad7da4f872acb3005727392631dab282423d1",
    "width": 640
    },
    {
    "height": 320,
    "url": "https://i.scdn.co/image/d9cf89b9db73b95ed15d9e29e30d0dd8afea23e2",
    "width": 320
    },
    {
    "height": 160,
    "url": "https://i.scdn.co/image/d9e514e15f4940c77029ef3b11291d557b345ae9",
    "width": 160
    }
    ],
    "name": "Bring Me The Horizon",
    "popularity": 76,
    "type": "artist",
    "uri": "spotify:artist:1Ffb6ejR6Fe5IamqA5oRUF"
    }
    ],
    "limit": 20,
    "next": null,
    "offset": 0,
    "previous": null,
    "total": 1
    }
    }

Because this then returns the Artist ID we can get the top tracks for that artist and play a preview:

Call the API with this URL (GET):

https://api.spotify.com/v1/artists/<ARTIST ID>/top-tracks?country=GB

From here we can then extract the URL of the preview and play it, all without authentication!

MichaelStoddart
  • 5,571
  • 4
  • 27
  • 49