This repository contains examples of using the Spotify Web API in both Python and JavaScript to interact with Spotify's music catalog. You will learn how to authenticate using OAuth and fetch track data to integrate Spotify's features into your applications.
By integrating the Spotify Web API into your applications, you can:
- Access rich music data, including songs, albums, artists, and playlists.
- Manage user playlists.
- Enhance user experience with personalized music recommendations.
This repository provides examples to get you started quickly in both Python and JavaScript.
- A Spotify Developer Account
- Python 3.x (for the Python example)
- Node.js (for the JavaScript example)
git clone https://github.com/yourusername/Spotify-Web-API-Integration.git
cd Spotify-Web-API-Integration
- Navigate to the
Python/
directory:cd Python
- Install the required dependencies:
pip install -r requirements.txt
- Update
app.py
with your Spotify Client ID and Secret:client_id = "your_client_id" client_secret = "your_client_secret"
- Run the Python script:
python app.py
- Navigate to the
JavaScript/
directory and openindex.html
in your web browser. - Edit
app.js
to add your Spotify Client ID and Secret:const client_id = 'your_client_id'; const client_secret = 'your_client_secret';
- Click the button in the HTML file to fetch and display track data.
The Python script (app.py
) uses the Spotify Web API to:
- Authenticate using the OAuth client credentials flow.
- Fetch track data for a specific track ID.
{
"name": "Track Name",
"album": {
"name": "Album Name"
},
"artists": [
{
"name": "Artist Name"
}
],
"duration_ms": 210000
}
The JavaScript code (app.js
) demonstrates:
- Obtaining an OAuth token in a web app.
- Fetching and displaying track data in the browser.
The fetched data is displayed directly on the web page when the "Fetch Track Data" button is clicked.
Both examples handle errors that may occur during API requests, such as authentication failures, rate limits, or network issues. Proper error messages are displayed to help debug and resolve issues.
This project is licensed under the MIT License - see the LICENSE file for details.