用Spotify的API按艺术家搜索的正确python语法是什么?也许我错过了一些显而易见的东西(盯着这个看太久了)
根据文档,需要标题“authorization”和参数“q”和“type”。
https://developer.spotify.com/web-api/search-item/
我所做的:
artist_name = 'Linkin%20Park'
artist_info = requests.get('https://api.spotify.com/v1/search', header = {'access_token': access_token}, q = artist_name, type = 'artist')
ERROR: TypeError: requests() got an unexpected keyword argument 'q'
然后我想,也许参数必须以列表的形式发送?公司名称:
^{pr2}$但是:
ERROR: TypeError: list() takes at most 1 argument (2 given)
@Ilja的回答很好。或者,您可以在URL中嵌入参数(因为只有两个参数,而且都相对较短),例如:
list是一个列表,而不是map和list的混合体,比如在PHP中。^{} builtin 接受0或1位置参数,这应该是iterable。我强烈建议你通过官方的tutorial。在
您可能正在使用python-requests库。为了传递查询参数,例如} of parameters as the ^{} argument :
q
参数,you'd pass a ^{注意headers参数must be in its plural form, not "header"。在
最后,您可能对spotipy感兴趣,它是spotifywebapi的一个简单客户端。在
@Ilja和@alfasin的答案提供了很好的指导,但似乎不再起作用了。在
您必须将
headers
参数改为authorization
,并添加字符串Bearer
。在这对我有用:
相关问题 更多 >
编程相关推荐