我正在尝试获取Spotify api访问令牌。
spotify api需要重定向URI。
使用Spotipy库,我可以获取访问令牌,该令牌将附加到指定的重定向URI。
我正在尝试获取该URL,因此不必手动复制粘贴该代码。
我尝试使用请求和httplib2,但结果却相同。 auth URL重定向到带有访问令牌的URL,但是尝试在python中获取该URL的方式是一种中间人url,如果单击该中间商URL,则会立即打开带有访问令牌的url,但尝试在python中跟随它只是保持自身的自重。 / p>
url = SpotifyOAuth(client_id=Spotify.CLIENT_ID,
client_secret=Spotify.CLIENT_SECRET,
scope=Spotify.SPOTIFY_ACCESS_SCOPE,
username=cls.username,
redirect_uri=cls.LOCAL_SERVER,
cache_path='/home/yovel/PycharmProjects/CasaBonita/CaseBonita/Data/SpotifyCache')
auth_url = url.get_authorize_url()
h = httplib2.Http()
h.follow_all_redirects = True
resp = h.request(auth_url, "GET")[0]
content_location = resp['content-location']
pprint(content_location)
response = h.request(content_location, "GET")[0]
r = response['content-location']
pprint(r)
a = h.request(r)[0]
pprint(a[content-location)
输出:
'https://accounts.spotify.com/login?continue=https%3A%2F%2Faccounts.spotify.com%2Fauthorize%3Fscope%3Dplaylist-modify-private%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252F0.0.0.0%253A7000%252F%26client_id%3Dc13f9174976545dc88adabebe21d7e56'
'https://accounts.spotify.com/login?continue=https%3A%2F%2Faccounts.spotify.com%2Fauthorize%3Fscope%3Dplaylist-modify-private%26response_type%3Dcode%26redirect_uri%3Dhttp%253A%252F%252F0.0.0.0%253A7000%252F%26client_id%3Dc13f9174976545dc88adabebe21d7e56'