Reputation: 15
I have developed a simple Django app, using Spotify API and Spotipy Authorisation (authorisation flow). This runs a localhost server where I click a simple button which creates a playlist in Spotify.
My issue however is in setting this up for an alternative user to login via their credentials and gain authorisation.
Atm, I have set this app up using a hardcoded cid and client secret within the views.py module (in the backend). This uses the following code to gain auth.
token = util.prompt_for_user_token(username, scope, client_id= cid, client_secret= secret, redirect_uri=r_uri)
My index.html file then links a button to this script so that when clicked, the playlist is created. I expect this index.html needs to be updated to allow the user to login to their own spotify account and to authorise their token. However I am unsure on how to update this or if I am on the right track.
Alternatively, I think I may need to restart the project using java to gain authorisation for another user or using Implicit Grant Auth method, if spotipy authorisation cannot be used.
Upvotes: 1
Views: 3519
Reputation: 51
Can’t respond to above comment directly but the flask cache handler can be changed to django cache handler with
https://github.com/plamere/spotipy/blob/master/spotipy/cache_handler.py
Upvotes: 0
Reputation: 22903
You won't be able to use prompt_for_user_token
for this because it is a helper meant to be used locally by a single user and will block the app if the signin process is not completed.
Have a look at this Flask python app and adapt it to make it work in Django. https://github.com/plamere/spotipy/blob/master/examples/app.py
It does everything you need:
Have fun!
Upvotes: 2
Reputation: 626
I am not very familiar with Spottily API , but what i would try to do it to get the user id as describe below:
https://developer.spotify.com/documentation/web-api/#spotify-uris-and-ids
from the client to the server using Ajax ,and then in the client
use the the Playlist API:
https://developer.spotify.com/documentation/web-api/reference-beta/#category-playlists
Upvotes: 0