Reputation: 31
I'm starting to code a project based on the spotify API in Python, using the Spotipy module. This is my code
import spotipy
from spotipy.oauth2 import SpotifyOAuth
import requests as rq
SPOTIPY_CLIENT_ID="..."
SPOTIPY_CLIENT_SECRET="..."
SPOTIPY_REDIRECT_URI="http://127.0.0.1:9090"
SCOPE = "playlist-read-private%20user-read-email"
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(client_id=SPOTIPY_CLIENT_ID, client_secret=SPOTIPY_CLIENT_SECRET, redirect_uri=SPOTIPY_REDIRECT_URI, scope=SCOPE))
user_playlists = sp.current_user_playlists()
for i in user_playlists["items"]:
print(i["name"])
So this code requires a user to grant permission to the app to see its playlists. The problem I'm having is that once I login with an account and grant permission, I can't find any way to change the user. Any clue how to do so? Thanks in advance
Upvotes: 3
Views: 740
Reputation: 19
When you execute this code you will find that a new cache file will be created wherever the file of your code is. The filename would be something like ".cache-'username' ". This cache file contains the access token you get. If you want to change the account, the simplest way would be deleting the file and re-running the code and logging with the different user account.
Note - You have to be careful to login with the same account which you mention in the code otherwise the access token would be of no use.
Hope you find this useful.
Upvotes: 1