Reputation: 365
My goal is to set up a jupyter notebook where I can analyze features using Spotify's web API. I looked at Python's Spotipy library and installed it. What I'm having trouble is getting a token and figuring out how to define the redirect_url. Is a redirect_url necessary if I simply want to run this on Jupyter notebook?
Am I supposed to clone the spotipy files and then go to util.py to set the parameters for client IDs and username?
Upvotes: 1
Views: 3940
Reputation: 10184
I successfully use this code in a Jupyter notebook to authenticate and make requests to Spotify's API with spotipy:
import spotipy
import spotipy.util as util
from spotipy.oauth2 import SpotifyClientCredentials
import spotipy.oauth2 as oauth2
market = [ "AD", "AR", "AT", "AU", "BE", "BG", "BO", "BR", "CA", "CH", "CL", "CO", "CR", "CY",
"CZ", "DE", "DK", "DO", "EC", "EE", "ES", "FI", "FR", "GB", "GR", "GT", "HK", "HN", "HU",
"ID", "IE", "IS", "IT", "JP", "LI", "LT", "LU", "LV", "MC", "MT", "MX", "MY", "NI", "NL",
"NO", "NZ", "PA", "PE", "PH", "PL", "PT", "PY", "SE", "SG", "SK", "SV", "TH", "TR", "TW",
"US", "UY", "VN" ]
CLIENT_ID = "< YOUR CLIENT ID HERE >"
CLIENT_SECRET = "< YOUR CLIENT SECRET HERE >"
credentials = oauth2.SpotifyClientCredentials(
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET)
token = credentials.get_access_token()
spotify = spotipy.Spotify(auth=token)
track = "coldplay yellow"
res = spotify.search(track, type="track", market=market, limit=1)
print(res)
Client ID and Secret you get from your Spotify Developer Account.
Upvotes: 3