1

我正在尝试使用spotipypbl库访问 Spotify 播放列表。后者见http://pbl.readthedocs.io/en/latest/

我有这个:

import sys
from pbl import *
import spotipy
import spotipy.util as util


def fetch(): #pbl methods here

    classic_rock = Sample(PlaylistSource('Rock Classics'), sample_size=10)
    new_music = Sample(PlaylistSource('New Music Tuesday'), sample_size=5)
    combined = Shuffler(Concatenate([classic_rock, new_music]))
    show_source(combined)

scope = 'playlist-modify-public'

if len(sys.argv) > 1:
    username = sys.argv[1]
else:
    print "Usage: %s username" % (sys.argv[0],)
    sys.exit()

token = util.prompt_for_user_token(username, scope, client_id='a_valid_id', client_secret='a_valid_secret', redirect_uri='http://localhost:8888/callback')

if token:
    sp = spotipy.Spotify(auth=token)
    fetch()

如果我绕过与 pbl 方法和pbl上面的函数调用相关的片段并继续,我被授予访问权限。

    results = sp.current_user_saved_tracks()
    for item in results['items']:
        track = item['track']
        print track['name'] + ' - ' + track['artists'][0]['name']
else:
    print "Can't get token for", username

否则访问被拒绝,我得到spotipy.oauth2.SpotifyOauthError: No client id

这里发生了什么?

4

0 回答 0