我有一个包含专辑信息的词典列表,我试图在Spotify中搜索,然后添加到用户保存的专辑中。我尝试遵循Spotipy文档中给出的示例,但是,通过Spotipy使用搜索功能时,我会遇到问题。
SCOPE = 'user-library-modify'
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, scope=SCOPE))
for album in newMusic:
albumName = album["Title"]
artistName = f"{album['Last Name']}+{album[' First Name']}"
getRecord = sp.search(q = f"artist:{artistName}&album:{albumName}", type='album')
print(getRecord)
在运行后提示时,我提供了重定向的URL,但这会为每张专辑结果提供401响应:
{
"error": {
"status": 401,
"message": "No token provided"
}
}
我有带有访问和刷新令牌的.cache文件,但仍然说没有令牌。我以为也许我正在错误地输入查询,但是我没有发现任何错误。这就是一个示例结束URL的外观:
https://api.spotify.com/v1/search?query=artist:band+name&album:album+name&type=album&offset=0&limit=10
我在这里做错了什么?我如何识别访问代码?
I have a list of dictionaries that contain album information which I'm trying to use to search within Spotify and then add to users' saved albums. I tried following the examples given in the spotipy documentation, however, I'm getting an issue when using the search function via spotipy.
SCOPE = 'user-library-modify'
sp = spotipy.Spotify(auth_manager=SpotifyOAuth(CLIENT_ID, CLIENT_SECRET, REDIRECT_URI, scope=SCOPE))
for album in newMusic:
albumName = album["Title"]
artistName = f"{album['Last Name']}+{album[' First Name']}"
getRecord = sp.search(q = f"artist:{artistName}&album:{albumName}", type='album')
print(getRecord)
I provided the redirect url when prompted after running, but this results in a 401 response for each album result as such:
{
"error": {
"status": 401,
"message": "No token provided"
}
}
I have the .cache file with the access and refresh tokens but it still says no token is provided. I thought maybe I was entering the query incorrectly, but I don't see anything wrong. This is how an example end url looks:
https://api.spotify.com/v1/search?query=artist:band+name&album:album+name&type=album&offset=0&limit=10
What am I doing wrong here? How can I get my access code recognized?
发布评论
评论(1)
找到了这个问题;查询输入格式是错误的。我发现了过去一个问题的答案,该问题解释了我的问题:
不需要单独声明(例如“ Artist:_”,“,”专辑:_”)。它们应该像:
奇怪的是,它们与Spotify API文档中的内容相矛盾,其中示例查询值以此为此:
示例值:示例值:
“ Remaster%20Track:Doxy+Artist:Miles%20davis”
Found the issue; the query entry format was wrong. I found this answer to a past question that explains my problem: Using python to get a track from the spotify API by using search Endpoint
The artist, album, etc. do not need to be declared separately (e.g. "artist: _", "album: _"). They should just be combined together like:
Weirdly, this contradicts what is in the Spotify API documentation where an example query value is given as such:
Example value:
"remaster%20track:Doxy+artist:Miles%20Davis"
https://developer.spotify.com/documentation/web-api/reference/#/operations/search