There are a variety of API’s that you can use to connect to real data to solve problems like what kind of beer is preferred in a certain region, or what kind of travel overseas has happened during the last few years. In my case I am curious about my spotify data.
The service that I would like to use is the Spotify. Someone would want to use this to determine any or all information about what they listen to the most. With this spotifyr package we can see everything about the data of the current new account that I made. We can get artists, albums or search by a unique song or ID of a song to see how many listens it has.
The Spotify setup for the API is quite simple. First you have to go to your account or make a new one (If you don’t want anyone else to see what you listen to) and click on the developer tab at the bottom of your dashboard. Then you are going to want to make an app so that you can be a “developer” allowing you to connect to an API. All the steps are described in the documentation tab of the developers window. Once you create the app and download and install the spotifyr package, you will be able to receive your client ID and the secret token to access that Specific account. After you have both you are good to go by using the code below. (FYI there are many other tutorials online that can explain how to connect to the Spotify API)
According to the Spotify here are the steps you can take (Again this is all online but I thought I would include it for conveience. The link for this information is: https://developer.spotify.com/documentation/web-api/concepts/authorization). Again note that this is all on Spotifys’ website:
1). The access token is a string which contains the credentials and permissions that can be used to access a given resource (e.g artists, albums or tracks) or user’s data (e.g your profile or your playlists).
2). Authorization refers to the process of granting a user or application access permissions to Spotify data and features (e.g your application needs permission from a user to access their playlists).
3). The app provides, among others, the Client ID and Client Secret needed to implement any of the authorization flows.
4). To do so, go to your dashboard on your developer Spotify location and click on the Create an App button.
5). Enter an App Name and App Description of your choice and put a tick in the Developer Terms of Service checkbox and finally click on CREATE. Your application is now registered, and you’ll be redirected to the app overview page.
6). The app overview page provides access to different elements: App metrics, such as daily and monthly active users or number of users per country. Note that the metrics are initially empty.
App Status. By default, your app will be in Development Mode with limits on the number of users who can install it, and the number of API requests it can make. Note that you can request an extension of this quota if needed by clicking on the Request Extension link.
App settings.
Client ID, the unique identifier of your app.
Client Secret, the key you will use to authorize your Web API or SDK calls.
7). Add a web domain or URL to the Website field. This will help users to obtain more information about your application. This doesn’t really matter, you can input a sample like: http://localhost:3000
8). Once you have finished updating the app settings, click on SAVE.
You will need code that allows you to receive your spotify connection. The code to do so can be seen below:
After you have the client and secret, you are ready to start using the spotifyr package!
This call to spotify is going out and getting the last 20 of my played songs. This can give someone a key insight to what someone likes and what kind of songs they listen to. In my case, it is classic rock. I also wanted to see the track popularity and I wanted to see it arranged in descending order to see which of my last 20 songs were the “most popular”.
track.name | track.popularity |
---|---|
Back In Black | 84 |
Summer Of ’69 | 82 |
Welcome To The Jungle | 82 |
You Shook Me All Night Long | 82 |
Smells Like Teen Spirit | 79 |
More Than a Feeling | 79 |
More Than a Feeling | 79 |
Eye of the Tiger | 78 |
Whole Lotta Love - 1990 Remaster | 77 |
Another One Bites The Dust - Remastered 2011 | 74 |
Sweet Emotion | 74 |
Born to Run | 73 |
You Really Got Me - 2015 Remaster | 70 |
For Those About to Rock (We Salute You) | 67 |
Smoke on the Water | 63 |
Carry on Wayward Son | 62 |
Don’t Stop Believin’ | 57 |
Crimson & Clover | 54 |
Rock And Roll All Nite | 38 |
Spark & Flame | 36 |
As you can see in my recently played songs, the most popular song is Back in Black with a track popularity rating of 84. As you can also see, all of my songs have to do with classic rock which is why most of them are rated so good ;).
With this function, we can get the audio features of an artist which include many fun variables like loudness, acousticness, tempo, whether it is explicit or not and my favorite being danceability. With this code I wanted to see what the top 30 songs by Pink Floyd regarding their danceability.
artist_name | track_name | danceability |
---|---|---|
Pink Floyd | The Happiest Days of Our Lives | 0.740 |
Pink Floyd | The Happiest Days Of Our Lives - 2011 Remastered Version | 0.731 |
Pink Floyd | Run Like Hell | 0.717 |
Pink Floyd | Two Suns in the Sunset | 0.714 |
Pink Floyd | Run Like Hell - 2011 Remastered Version | 0.714 |
Pink Floyd | Two Suns In The Sunset - 2011 Remastered Version | 0.708 |
Pink Floyd | Free Four - 2011 Remastered Version | 0.698 |
Pink Floyd | A Spanish Piece | 0.697 |
Pink Floyd | Free Four | 0.695 |
Pink Floyd | Another Brick in the Wall, Pt. 2 | 0.693 |
Pink Floyd | Another Brick In The Wall, Pt. 2 - 2011 Remastered Version | 0.693 |
Pink Floyd | San Tropez | 0.691 |
Pink Floyd | San Tropez - 2011 Remastered Version | 0.689 |
Pink Floyd | A Spanish Piece - 2011 Remaster | 0.689 |
Pink Floyd | Childhood’s End | 0.673 |
Pink Floyd | Childhood’s End - 2011 Remastered Version | 0.672 |
Pink Floyd | Pigs on the Wing 1 - 2018 Remix | 0.671 |
Pink Floyd | Pigs On The Wing 1 - 2018 Remix | 0.671 |
Pink Floyd | Pigs on the Wing 1 | 0.664 |
Pink Floyd | Pigs On The Wing 1 - 2011 Remaster | 0.662 |
Pink Floyd | Another Brick in the Wall, Pt. 3 | 0.653 |
Pink Floyd | Another Brick In The Wall, Pt. 3 - 2011 Remastered Version | 0.649 |
Pink Floyd | Another Brick In The Wall (Part 2) - Live | 0.638 |
Pink Floyd | Goodbye Blue Sky | 0.638 |
Pink Floyd | Goodbye Blue Sky - 2011 Remastered Version | 0.638 |
Pink Floyd | Another Brick In The Wall (Pt. 2) - Live, 2018 Remaster | 0.630 |
Pink Floyd | Another Brick in the Wall, (Pt. 2) - Live | 0.628 |
Pink Floyd | Party Sequence | 0.628 |
Pink Floyd | Young Lust | 0.615 |
Pink Floyd | Young Lust - 2011 Remastered Version | 0.615 |
With this table you can see that Pink Floyds’ most danceable song is The Happiest Days of Our Lives. I’m not much of a dancer but ill take the codes word for it. I could of used any artist that I wanted to see which is pretty cool.
Spotify’s API is very cool and can do many different things. You can see all of the functions listed by going to the help tab in the bottom right console. As you can see there is a variety of cool functions that can answer a lot of questions regarding a spotify playlist.