Spotify API OAuth - Automate Getting User Playlists (Complete Tutorial)

preview_player
Показать описание
In this tutorial, you will build a Python program to automate getting a users playlists from the Spotify API using OAuth.

We'll cover the API Reference, Authorization (Access Tokens, OAuth), Rate Limits. I will walk you through the parts of the API that let you retrieve songs, albums, playlists from the Spotify API.

I will explain OAuth 2.0 Authentication for REST APIs. We will go through the process of retrieving an access token and writing code to refresh that token from the Spotify API.

📚 MY FAVOURITE PROGRAMMING BOOKS 📚

⌨️ MY DESK SETUP (I ACTUALLY USE) ⌨️

📹 CREATOR SETUP 📹

📱 GET IN TOUCH:

❤️ LIKE
It takes me a long time to make these videos, please give the video a thumbs up 💪

🎬 WATCH NEXT

✅ SUBSCRIBE:

ℹ️ ABOUT THIS VIDEO:
In this video, we'll go over how you can get the currently playing track with the Spotify API. This was a requested video to build a Discord bot to get the currently playing song via the Spotify API. This Python tutorial will help you to build your applications with the Spotify API using React/Flutter/Javascript.

In later videos we will look at Spotify API Authorization flows such as OAuth and Access Tokens.

TIMESTAMPS:
00:00 What we're building
01:30 Navigating the Spotify Web API (Authorization, Scopes, Rate Limits)
01:26 Exploring the Spotify Web API Documentation
04:13 Spotify API Reference (Albums, Tracks, Artists, Playlists)
06:37 Spotify API (Console Demo)
07:40 Spotify API Authorization (Which OAuth 2.0 Flow?)
09:52 OAuth 2.0 Explained (The Only Explanation You'll Ever Need)
14:20 Setting up the Python Project (VSCode) & Installing Dependencies (Flask)
17:00 Creating an App on the Spotify API Developer Dashboard
18:30 Setting up the Flask Server & Flask Session
21:30 Getting the Client ID & Secret from the Spotify Developer Dashboard
22:04 Creating our first page
23:05 - Creating the endpoint for 'Login with Spotify'
28:37 - Creating the OAuth 2.0 Callback endpoint for Spotify API
39:03 - Using the Spotify OAuth 2.0 Access Token to Get User Playlists
43:35 - Refreshing the Spotify OAuth 2.0 Access Token (using refresh_token)
49:15 - Running our Flask app
51:18 - Testing our 'refresh token logic'
55:25 - Closing out (subscribe for more projects)
56:16 - Why I didn't use the Spotipy OAuth Spotify API Library

💁🏽‍♂️ WHO AM I:
I'm Imdad, a startup founder and CTO in London, UK. I love making videos about life as a technical cofounder, teaching people to code through cool programming projects and productivity.

I even teach Python tutorials as it is a great programming language that's used by the likes of Google, Facebook, Twitter, Quora and pretty much every big tech company you can name.

#spotifyplaylist #spotifytutorial

Disclaimer: The links above are affiliate links. If you decide to purchase any of these products through my links, I'll receive a small commission at no extra cost to you. This helps support my channel, and I only recommend products that I've personally used and believe in.
Рекомендации по теме
Комментарии
Автор

This is such an incrediblly helpful video! I love that you take the time to explain what each bit of code is doing and why you are using it. I really felt like I learned how to properly interact with the Spotify API and make it do what I needed, not just follow a tutorial and end up with a 1:1 copy of your code.

finn
Автор

Great video, you did a great job explaining every piece of code! I was wondering if you could share the source code? I am currently implementing a project related to this and it would be of great help, thank you and keep up the good work!

edwintrejo
Автор

Love how composed you are when explaining. Thank you so much for the video. God bless!

AfaAziz-ykfp
Автор

Amazing video, only point of feedback I have would be to run the code at some points before the very end, could be daunting for some people to see the code crash at the very end and not know where to start debugging! Loved the OAuth explanations, they were great!

ivbplays
Автор

Hello! For few days, I was trying to use YouTube API and Spotify API for a converter, it authenticates the user but during the redirection. My always get an error in localhost, can’t reach website. Do you know how to fix that problem, basically my localhost isn’t working properly. Thank you. Nice video

ErenEsinler
Автор

Hey, this is an amazing video. I think Flask documentation has changed as some of the imports used like 'request' and 'session' do not work in the new flask. These are my new import statements:
from flask import Flask, redirect, Request, jsonify
from flask_session import Session

I also had to run pip install flask-session for importing Session.

krnotveryjetty
Автор

Around the 29 minute mark there are a bunch of other imports that were never mentioned earlier in the vid, luckily caught and added as I was following along, but may want to put that in the video.

AndrewSchneider-hb
Автор

Excellent video. You've explained a tricky subject very clearly, and this is a great advert for using Python to solve a Web API problem, a programming technology I had not considered using before. Thanks very much.

drg
Автор

Have been looking for a tutorial like this for ages. Thanks!!

kiyeidowu
Автор

I actually used this video to help with making a react project with spotify's api and it was still incredibly helpful. Great video!

murtleturtle
Автор

when session first appears at line 56, has it ever been defined before? following along I get an error when trying to assign values to session

NightRainLily
Автор

Hey man! Currently struggling quite hard with authentication, i decided to use Auth code with PKCE, yet im having an issue when getting the code from the urlParameters, as they are showing up as empty. Would you please considering making a part 2 where you use Auth code with PKCE, instead of normal auth code? I would be very thankful. Great video!

GianlucaGallino
Автор

Thank you! you made everything so clear to understand. just one thing, 3600s is an hour, not a day😅

chaotang
Автор

you seem to know a lot about spotify- and I have a question. knowing almost nothing about python or coding in general, I would love to see a program that at a click of a button/click of a key, it adds the song that is currently playing to a playlist.

restart_life.
Автор

thanks for your videos using the Spotify API! I've just started a project and am new to it, your clear and detailed explanations were so helpful!

elisad.
Автор

Hey @imdadcodes, I'm fairly new to coding with the spotify API, and I was trying to follow your old video from 3 years ago where you automate spotify to save youtube playlists to spotify playlists. Unfortunately since spotify updated their documentation page when I go to the "Save tracks for user" tab it no longer shows the oAuth token and the "get token" button is no longer there. How would I go about getting this token now since I'm still looking to complete that tutorial for my own personal use.

avyi
Автор

so i implemented this into my flask social media website, but i dont know how to create different instances for different users. basically, no matter what account i log into it is now logged into my spotify as well

adamrajkotwala
Автор

I was redirected to the Spotify login, my account was automatically showed up with correct link information. I accepted the terms, and the Spotify site gave me an error message(It just says Error) and provided a link to the support section.

_Tech_
Автор

That was great, I really appreciate that you deeply go into explaining all the concepts.
Thanks a lot! :)

amatacz
Автор

This was super helpful, thanks! Do you have the github link for this code?

Ethanthest