Example #1
0
def connect_spotify_callback():
    code = request.args.get('code')
    if not code:
        raise BadRequest('missing code')

    try:
        token = spotify.get_access_token(code)
        spotify.add_new_user(current_user.id, token)
        flash.success('Successfully authenticated with Spotify!')
    except spotipy.oauth2.SpotifyOauthError as e:
        current_app.logger.error('Unable to authenticate with Spotify: %s', str(e), exc_info=True)
        flash.warn('Unable to authenticate with Spotify (error {})'.format(e.args[0]))

    return redirect(url_for('profile.connect_spotify'))
def connect_spotify_callback():
    code = request.args.get('code')
    if not code:
        raise BadRequest('missing code')
    sp_oauth = spotify.get_spotify_oauth()

    try:
        token = sp_oauth.get_access_token(code)
        spotify.add_new_user(current_user.id, token)
        flash.success('Successfully authenticated with Spotify!')
    except spotipy.oauth2.SpotifyOauthError as e:
        current_app.logger.error('Unable to authenticate with Spotify: %s', str(e), exc_info=True)
        flash.warn('Unable to authenticate with Spotify (error {})'.format(e.args[0]))

    return redirect(url_for('profile.connect_spotify'))