This is a repository of the web app Spotivey, which was developed in the context of a master's thesis submitted at the Audio Communication Group of TU Berlin. It allows music listening data retrieval from Spotify user accounts within scientific online questionnaire studies. For academic scholars only, fully user-transparent & GDPR-compliant. No retrieval of personal data (name, email, gender, birthdate).
Ladleif, M., Lepa, S. Spotivey – eine Web-Applikation zur vereinfachten Nutzung der Spotify-API für Online-Fragebogenstudien. Publizistik (2023). https://doi.org/10.1007/s11616-023-00790-y
Since music listening nowadays happens increasingly via streaming services such as Spotify, Apple Music or Amazon Music, it would be technically possible to perform research on music actually listened to on basis of 'digital traces' left behind (Greenberg & Rentfrow, 2017), instead of relying on self-reporting in questionnaires, a strategy which suffers from various validity issues (Lepa et al., 2020). In principle, open APIs offered by music service providers could be used for this purpose. For example, by using the Spotify API, it is possible to obtain a wide range of music-related user account information, such as the music tracks most recently listened to, favorite songs or artists, as well as artists followed or playlists created. However, using the Spotify API is normally not possible without technical knowledge of web programming. In addition, purely music-related transaction data without further socio-demographic contextual information is only helpful for academic research to a limited extent. A final problem is that streaming accounts are often used by several people at the same time, which makes it hard to attribute usage data to a specific person.
To address these challenges, the web application Spotivey was developed. It allows to easily integrate most user data retrieval functions of the Spotify API within an online survey (e.g. the open source survey creation tool LimeSurvey) in compliance with EU data protection regulations. In this way, individual music usage data can be fetched without web programming knowledge and linked directly with socio-demographic information from a questionnaire (see Figure 1). Optionally, it is possible to ask survey participants to confirm individual results of Spotify data retrieval via a separate window, for example to exclude transactional data stemming from another person using the same account. Furthermore, Spotify helps to automatically create LimeSurvey questions with reference to the collected music usage data for an optional follow-up online survey to be administered directly following data retrieval. For example, if the participants' last 20 songs listened to were fetched, their perceived emotional expression could then be asked for via rating items and a web music player. In general, results from Spotify API queries may be either displayed in the user area of Spotivey for a quick overview or downloaded together with the survey respondent ID in a CSV file for extended statistical analyses.
Fig. 1: Individual music usage data can be linked directly with socio-demographic information from a questionnaire
First you need to create a Django project. You can use the tutorial for this.
Then urlpatterns must be adapted and include imported into urls.py:
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('api.urls')),
path('', include('frontend.urls')),
path('spotify/', include('spotify.urls')),
]
You now have to add the following lines to the INSTALLED_APPS in settings.py.
'api.apps.ApiConfig',
'spotify.apps.SpotifyConfig',
'frontend.apps.FrontendConfig',
'rest_framework',
'<name-of-your-project>'
Change <name-of-your-project> to your project name
You can also change other settings that are recommended, see the documentation.
In the next step, load the repository into your project folder and install the necessary packages.
- cd to the directory where requirements.txt is located
- activate your virtualenv
- run:
pip install -r requirements.txtin your shell.
Once you have installed all the necessary packages, you can test whether the code runs locally. To do this, go through the following steps.
- cd to the directory where manage.py is located
- run:
python ./manage.py makemigrations - run:
python ./manage.py migrate - run:
python ./manage.py runserver
You should now see the Spotivey user interface at http://127.0.0.1:8000/login.
Spotivey does not work yet. There are still a few steps missing.
Before we can use Spotivey and its functions, a Spotify Developer account must have been created. To do this, go to the Spotify for Developers page.
Once you have logged in, create a new app. Now give the app a suitable name (e.g. “Spotivey”) and a fully transparent description. We recommend the following:
Web app hosted at XXX, allows music listening data retrieval within scientific online questionnaire studies.
For academic scholars only, fully user-transparent & GDPR-compliant.
No retrieval of personal data (name, email, gender, birthdate).
Afterwards, each developer app has a client ID and a client secret. These are to be kept secret.
Finally, change the setting by adjusting the Redirect URIs. Here you name the URLs to which Spotify redirects. Once within the survey (/spotify/redirect) and once within the results page (/spotify/redirect2).
For local use/testing of the app without a server, the localhost (e.g. http://127.0.0.1:8000/spotify/redirect and http://127.0.0.1:8000/spotify/redirect2) is named.
Note: Two redirect URLs must always be used
Once you have two REDIRECT_URI, the CLIENT_ID and the CLIENT_SECRET, now create a Credentials.py file and add it to the /spotify folder. Now add
CLIENT_ID = "YOUR CLIENT_ID"
CLIENT_SECRET = "YOUR CLIENT_SECRET"
REDIRECT_URI = "YOUR REDIRECT_URI"
REDIRECT_URI2 = "YOUR REDIRECT_URI2"
Finally, change in ./spotify/views.py line 148
There are a variety of ways to deploy Spotivey to a server. First, you should check Django's deployment checklist.
One possibility we are suggesting here is that the Django app is integrated into Apache using Phusion Passenger (libapache2-mod-passenger). This also works as a standalone or NGINX variant.
For more information have a look at the following documentation
Spotivey offers an admin area. To access it, an admin must be created using the command python ./manage.py createsuperuser.
The admin area is accessible under the URL extension /admin.
There you can give users administrative rights, check the results and delete them if necessary.
For more information, see the Django website.