关于Django授权的Spotipy,无需复制粘贴到控制台 [英] Spotipy on Django authorization without copy-paste to console

查看:73
本文介绍了关于Django授权的Spotipy,无需复制粘贴到控制台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Django网站,我想在其中使用Spotipy查找歌曲的统计信息,例如受欢迎程度和观看次数.我现在有以下代码:

I have a Django site in which I want to use spotipy to look for statistics of the song like popularity and views. I have this code right now:

import spotipy
import spotipy.util as util #luxury
import json
import webbrowser

username = 'dgrqnco2rx8hdu58kv9if9eho'
scope = 'user-read-private user-read-playback-state user-modify-playback-state'

token = util.prompt_for_user_token(username, scope, client_id='08bb526962574a46b359bffc56048147',
                                       client_secret='bf6d4184c8ae40aca207714e02153bad', redirect_uri='http://google.com/')

sp_obj = spotipy.Spotify(auth=token)
ss = 'name of song'
if ss.__contains__('('):
    q = ss[0:ss.index('(')]
elif ss.__contains__('['):
    q = ss[0:ss.index('[')]
elif ss.__contains__('['):
    q = ss[0:ss.index('{')]
else:
    q = ss
query = sp_obj.search(q, 1, 0, 'track')

#<<<<<<<<<<SONG>>>>>>>>>>

#FIND THE SONG URI
song_uri = query['tracks']['items'][0]['uri']

track = sp_obj.track(song_uri)
track_data = sp_obj.audio_features(song_uri)

song_popularity = track['popularity']
song_danceability = track_data[0]['danceability']
song_energy = track_data[0]['energy']
song_loudness = track_data[0]['loudness']
song_tempo = track_data[0]['tempo']

但是Spotipy将我重定向到页面进行授权,我需要将URL粘贴到控制台中.但是,普通用户无权访问此控制台.那么我该如何以其他方式进行授权,甚至绕过授权?

However spotipy redirects me to a page for authorization and I need to paste the url in the console. The regular user however does not have access to this console. So how can I do the authorization in an alternative way or even bypass it?

我当时正在考虑获得一个Spotify帐户,每个用户都将在该帐户中登录,这样该用户就不必进行授权,也不必拥有Spotify帐户.这可能吗?如果没有,我还能尝试什么?

I was thinking about getting a spotify account in which every user will be getting logged in so that the user won't have to do the authorization and won't have to have a spotify account. Is this possible? If not what else can I try?

推荐答案

您不能使用 util.prompt_for_user_token ,因为它仅是本地使用的帮助.

You can't use util.prompt_for_user_token because it's just a helper for local usage only.

您需要将代码安排为API端点,以便多个用户可以登录.这是一个完整的示例,允许多个用户登录

You need to arrange your code as API endpoints so that multiple users can sign in. Here is a full working example that would allow multiple users to sign in https://github.com/plamere/spotipy/blob/master/examples/app.py.

它使用Flask,但您可以轻松地使其适应Django.

It uses Flask but you can easily adapt it to Django.

这篇关于关于Django授权的Spotipy,无需复制粘贴到控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆