mirror of
https://github.com/spotipy-dev/spotipy.git
synced 2026-04-26 16:15:51 +03:00
[GH-ISSUE #852] Web-app with user logins for playlist creation #524
Labels
No labels
api-bug
bug
dependencies
documentation
duplicate
enhancement
external-ide
headless-mode
implicit-grant-flow
invalid
missing-endpoint
pr-welcome
private-api
pull-request
question
spotipy3
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/spotipy#524
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @ccolas on GitHub (Sep 9, 2022).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/852
Hi,
I'm building an app to create playlists, so I need the app users to log in and give me the right to do so.
I want to host it on huggingface's spaces (https://huggingface.co/spaces).
Locally, my app works well, it opens a log in page and I can create my playlists. I use:
Now I want to put it online. I update the SPOTIPY_REDIRECT_URI to the home page of my app both on the dashboard and in the app script.
Here is the error I get:
This seems related to this issue and to that one
From what I read there, this has to do with the fact that the server cannot open a new tab for the login page. There seem to be some complicated trick to generate a long-term token for a given user (me), then to use that to connect.
But I want to have many users and I can't ask them to each go through the generation of this long term token.
So what's the solution? For sure there must be a way to build a non-local spotify app that requires users login and allows playlist creation.
What did I miss?
@git-eri commented on GitHub (Sep 10, 2022):
I think you have multiple problems with your project but let me give you some tipps to improve and work with the spotify authorization scheme.
Take a good look at session handlers and how the spotify authorization flow works. Especially if you are using Flask you can take very valuable informations from the example using the FlaskSessionCacheHandler app.py. That one works great example to extend with your own ideas.
Your current app depends on sending back the url spotify gives you to your app. But there is a way simpler method by using cache-/session handlers.
Then the cache handler will store the auth & refresh token for you for every session, that is how i understood it worked.
Then your users just have to login with spotify and you will be redirected to your app automatically and the user gets a cookie assigned. If you don't use Flask you can use Redis for example.
I myself got most of the informations to build a multi-user app from the examples so i hope i could help you out.
(If you are using Flask and are trying to use the FlaskSessionCacheHandler please refer to this issue#838)
@ccolas commented on GitHub (Sep 13, 2022):
Thanks, I checked the cache handler stuff and found a way to achieve what i wanted.
Here it is with comments.
@jamesschiffres commented on GitHub (Oct 18, 2022):
@ccolas running into the same issue - where is StreamlitCacheHandler being imported from? also where does the 'session' argument come from? I am using Django
@ccolas commented on GitHub (Oct 18, 2022):
The StreamlitCacheHandler is a copy paste from the Flask one I defined myself:
With streamlit, the session is streamlit.session_state. It's a dict that stays cached across page reloads. I'm assuming Django has something similar, so you should use this.
@sutaminajing40 commented on GitHub (Mar 6, 2023):
@ccolas
I have a question about one previous code.
I use streamlit to create web apps.
Is the 'session' argument in line 2 flask.session? And what does the return sp in the last line mean?
@ccolas commented on GitHub (Mar 7, 2023):
hi
the session argument is streamlit's session state:
streamlit.session_state. If you use streamlit you might not need flask? I don't know how flask works.sp is the spotify client, once created you can use it with the spotify api, eg
sp.recommendation_genre_seeds()['genres']gives you the list of spotify genres, etc.@sutaminajing40 commented on GitHub (Mar 12, 2023):
@git-eri
@ccolas
Thanks for the reply.
I have made the following changes to my code to make use of what I have been taught.
However, the following error code is displayed.This was found to be the case with the variable 'sp' not containing any authentication information, i.e. the authentication was not successful. Is there anything wrong with my code?