From Beats to Data: An Easy Guide to Spotify’s API
Table of Contents
- Introduction
- Get Started
- Jupyter Notebook
- Results
- Conclusion
- References
Introduction
Spotify is a digital music, podcast, and video service that gives you access to millions of songs, and other content from creators all over the world. Spotify’s platform revolutionized music listening when it was launched in 2008, and since then, more listeners have discovered, managed, and enjoyed over 100 million tracks, 5 million podcasts titles, and 350,000 audiobooks on Spotify. Without a doubt, we can say that Spotify is the most popular audio streaming subscription service with more than 574 million users, including 226 million subscribers in over 180 markets (Spotify, 2023).
So, besides all the cool things we’ve got from this app, there are a few things that we can retrieve, which you might not know about until now. These are things that will allow us to get to know ourselves a little bit better. If you’re a music lover, like me, you might have wondered, “Who is indeed my favorite artist?”, or maybe“What’s my favorite song?” but don’t worry because that’s in the past.
In this post, you will learn how to retrieve data from you Spotify Account using the Spotify API. In this case, I’ll show you how to get data of your current top artists, current top tracks, the recently liked, or saved, tracks and more…
Get Started
First things first. This guide assumes you have a Spotify account (free or premium). Now, if you want to interact with this API, you have to follow these instructions.
Log in into the dashboard using your Spotify account. It will look like this:
Then, hit on Create app button:
In this part
- You have to name your App
- Add a description
- The Website is not required so don’t be afraid of not filling it
- For this project, we’ll use the Redirect URI as http://localhost:8888/callback
- You can ignore the boxes of Which API/SDKs are you planning to use
- Finally, you must agree with terms of service
Once you’ve done this, you’re going to see something like this:
Now, you have to hit the Settings button, this is to get the API’s credentials as you can see below:
Now that you’re here, hit on the View client secret:
In this part, you have to copy the Client ID and the Client secret, and paste it into a credentials.txt (with the same name) file.
Jupyter Notebook
Just before running the notebook, remember to install, or have installed, the following libraries:
pip install spotipy
pip install requests
pip install plotly
Below is my reusable function. Also, remember that the credentials.txt file has to be in the same directory of the notebook. After that, you’re ready to go.
Results
Since Medium can’t support interactive charts, here we’ll see the static charts we’ve got from our notebook. Also, since this is an easy guide, the graphs are going to be treemaps to make the representation the easiest possible. Remember, there’s a lot of ways to visualize data.
Conclusion
This is an interesting API that you can work with. There’s still so many things that you can use from it, and there’s a lot of information that you can retrieve from your profile that can help you to create a lot of new things to use them in your life. For example, extract information from a pre-existing playlist and see if it’s going to be a banger for your party based on the information that each song has.
So, even though this API has a lot of potential, there’s a few things that might be a little bit tricky, and most of them are not easy to catch at first either; but don’t worry, you’ll learn these things on the journey. Finally, I hope this helps you to get to know it better, and please check the references I used if you get stuck while using the API.
References
- Spotify — About Spotify. (2023, October 24). Spotify.
- https://newsroom.spotify.com/company-info/
- Freidenburg, M. (2023, October 21). A Data Art Project: the Spotify July Top 50 | Medium. Medium; Medium.
- https://medium.com/@miafreidenburg/spotify-top-50-689a37c90b7c
- spotipy-dev/spotipy: A light weight Python library for the Spotify Web API. (2023, October 31). GitHub.
- https://github.com/spotipy-dev/spotipy#readme