(spotipy) 方法永远不会完成,因为它最终会出现在 oauth redirect url 的视图中
(spotipy) method never completes because it ends up at oauth redirect url's view
我正在尝试使用 spotipy 执行来自 Spotify 的搜索请求。我在 bash_profiles 中指定了客户端 ID、秘密 ID 和重定向 url (http://127.0.0.1:8000/callback/q),如 API.
中所述
def search(username, query):
token = util.prompt_for_user_token(username, scope) #like oauth with redirect url
print("received token response")
if token:
sp = spotipy.Spotify(auth=token)
return sp.search(query, 1, 0, type='track')
问题是我正在使用 django,这也迫使我在 urls.py 中指定重定向 url 并在 views.py
中指定相应的视图
[from urls.py...]
url(r'^callback/q$', views.callback, name='callback'),
[from views.py...]
def callback(request):
print("callback view reached")
return render(request, 'rec/search.html')
似乎 django 然后拦截显示来自重定向的视图-url,所以我的搜索方法从未完成执行。我对如何获得需要重定向 url 的令牌感到有些困惑,然后继续执行授权请求后的其余方法
我不确定这是否有帮助,但我放弃了通过 util.prompt_for_user_token 进行的身份验证,转而使用 this basic implementation。它是在 bottle 中实现的,但应该相对容易转换为 django 和您的特定需求。我也希望这样做。
我正在尝试使用 spotipy 执行来自 Spotify 的搜索请求。我在 bash_profiles 中指定了客户端 ID、秘密 ID 和重定向 url (http://127.0.0.1:8000/callback/q),如 API.
中所述def search(username, query):
token = util.prompt_for_user_token(username, scope) #like oauth with redirect url
print("received token response")
if token:
sp = spotipy.Spotify(auth=token)
return sp.search(query, 1, 0, type='track')
问题是我正在使用 django,这也迫使我在 urls.py 中指定重定向 url 并在 views.py
中指定相应的视图 [from urls.py...]
url(r'^callback/q$', views.callback, name='callback'),
[from views.py...]
def callback(request):
print("callback view reached")
return render(request, 'rec/search.html')
似乎 django 然后拦截显示来自重定向的视图-url,所以我的搜索方法从未完成执行。我对如何获得需要重定向 url 的令牌感到有些困惑,然后继续执行授权请求后的其余方法
我不确定这是否有帮助,但我放弃了通过 util.prompt_for_user_token 进行的身份验证,转而使用 this basic implementation。它是在 bottle 中实现的,但应该相对容易转换为 django 和您的特定需求。我也希望这样做。