如何在Spotify,Python API中工作?

瓦萨尔肉饼

我已经按照以下说明在机器上安装了Spotipy:https//github.com/plamere/spotipy

我正在尝试运行示例之一,但仅打开文件就没有任何反应。这是他们提供的代码:

显示有关URN或URL的艺术家信息

import spotipy
import sys
import pprint

if len(sys.argv) > 1:
    search_str = sys.argv[1]
else:
    search_str = 'Radiohead'

sp = spotipy.Spotify()
result = sp.search(search_str)
pprint.pprint(result)

当我在cmd提示符下键入“ search.py​​”时,文件打开。什么都没发生。我以为它会打印出与Radiohead相关的内容,但不会。

我还需要做其他事情吗?

更新10/28/2017

我确保已安装请求包。

我收到很多错误,看来client.py给了我错误。它还说我需要提供一个令牌,但是此代码不需要令牌。

Python命令和Spotipy错误

eyllanesc

Error 401 is generated when you try to access a resource and you are not authenticated. Spotify currently requires that you provide your credentials for it you must register in the following link and create an application in it, in the end it will provide you with the Client ID and Client Secret, these values must be placed in the part indicated by the code.

import sys
from spotipy.oauth2 import SpotifyClientCredentials
import spotipy
import pprint

if len(sys.argv) > 1:
    search_str = sys.argv[1]
else:
    search_str = 'Radiohead'

client_id = "your_client_id"
client_secret = "your_client_secret"

client_credentials_manager = SpotifyClientCredentials(client_id=client_id, client_secret=client_secret)
sp = spotipy.Spotify(client_credentials_manager=client_credentials_manager)

result = sp.search(search_str)
pprint.pprint(result)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章