Spotipy -401代币错误;使用.Search函数

发布于 2025-01-22 15:56:12 字数 893 浏览 4 评论 0 原文

我有一个包含专辑信息的词典列表,我试图在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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不寐倦长更 2025-01-29 15:56:12

找到了这个问题;查询输入格式是错误的。我发现了过去一个问题的答案,该问题解释了我的问题:

不需要单独声明(例如“ Artist:_”,“,”专辑:_”)。它们应该像:

https://api.spotify.com/v1/search?query=first+name+last+name+album+title&type=album&offset=0&limit=10

奇怪的是,它们与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:

https://api.spotify.com/v1/search?query=first+name+last+name+album+title&type=album&offset=0&limit=10

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文