I am trying to take the billboard top 100 songs from a given date and generate a spotify playlist. I have replaced my client ID and secret with random values for privacy. When I execute the code below, I am expecting a browser to pop up that asks me to agree to spotify conditions. I have edited the settings in the developer tab in spotify to the redirect URI below and have obtained the correct client ID and secret from my account.
Help greatly appreciated.
import requests
from bs4 import BeautifulSoup
import spotipy
from spotipy.oauth2 import SpotifyOAuth
CLIENT_ID = "abcde"
CLIENT_SECRET = "1234"
date = input("What year do you want to travel to? Type the date in this format YYYY-MM-DD")
URL = f"https://www.billboard.com/charts/hot-100/{date}/"
response = requests.get(URL)
webpage = response.text
print(webpage)
soup = BeautifulSoup(webpage, "html.parser")
title = soup.select("li ul li h3")
song_list = [title[song].getText().strip() for song in range(0,100)]
print(song_list)
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="CLIENT_ID",
client_secret="CLIENT_SECRET",
redirect_uri="http://example.com",
scope="playlist-modify-private",
show_dialog = True,
cache_path = "token.txt")
)
user_id = sp.current_user()["id"]
You have
spotipy.Spotify(auth_manager=SpotifyOAuth(client_id="CLIENT_ID",client_secret="CLIENT_SECRET",
in your code, but you need to remove the "quotes" around those variables. Else they are the strings "CLIENT_ID" and "CLIENT_SECRET".
You are literally a godsend. I have been wondering what the heck is wrong with my code for like 5 days now. Thank you kind stranger!!
Hey there you, Yeah, you! 😁 Welcome - we're glad you joined the Spotify Community! While you here, let's have a fun game…