spotipy-dev / spotipy

A light weight Python library for the Spotify Web API
http://spotipy.readthedocs.org
MIT License
5.01k stars 957 forks source link

How can I send redirect uri to user and why my app is stuck #1018

Closed Vitek14 closed 1 year ago

Vitek14 commented 1 year ago

Hi, I'm trying to make a discord bot(disnake) with spotipy, but for most things i need redirect uri. I passed it, but when the user calls command with authorization, my bot stucks every time until log in. How can i remove freezes? And another question: How can user get link to authorize app? Code:

    async def like_button(inter):
        # Creating *Bot thinking...* to avoid interaction stuck, where inter - interaction, when user press button
        await inter.response.defer()
        ...some_code
        sp = spotipy.Spotify(auth_manager=SpotifyOAuth(
            client_id=spotify_client,                               # From database
            client_secret=spotify_secret,                           # From database
            redirect_uri="http://localhost:8888/callback",
            scope="user-library-modify",
            cache_handler=spotipy.MemoryCacheHandler()
        ))
        sp.current_user_saved_tracks_add(tracks=current_tracks[0])  # Adding current track to favorites. STUCK ON THIS LINE
        await inter.followup.send("Success")
        ...some_code

I'm sorry if something is wrong in code

Vitek14 commented 1 year ago

Solved! I did this using SpotifyOAuth().get_authorize_url() I send the link to the user and write the token to the database