【发布时间】:2020-12-10 02:45:51
【问题描述】:
搜索是否已有答案:否
1.总结问题
Spotify 引入了获取有关播客和节目信息的功能。 Details here.
我正在使用 Python“requests”包生成请求 URL,以获取诸如 no_of_followers 等指标(我不确定它们是否可用于播客),因此我尝试获取节目的元数据。
我用来获取节目信息的端点:GET https://api.spotify.com/v1/shows/{id}
headers = {
"Authorization": f"Bearer {access_token}"
}
# endpoint used "https://api.spotify.com/v1/shows/{id}"
lookup_url = "https://api.spotify.com/v1/shows/3IM0lmZxpFAY7CwMuv9H4g" #"The Daily" podcast example
print(lookup_url)
r = requests.get(lookup_url, headers=headers)
print(r)
print(r.status_code)
print(r.json())
但是我收到以下错误响应:
https://api.spotify.com/v1/shows/3IM0lmZxpFAY7CwMuv9H4g
<Response [404]>
404
{'error': {'status': 404, 'message': 'non existing id'}}
最后的问题
2。描述你的尝试
我尝试使用搜索端点提取类似信息,但确实得到了有效响应。搜索艺术家时信息丰富且符合预期,但我搜索的节目似乎缺少响应数据。
我用来搜索节目/艺术家的端点:GET https://api.spotify.com/v1/search
使用搜索端点查找有关节目/艺术家的信息:
headers = {
"Authorization": f"Bearer {access_token}"
}
endpoint = "https://api.spotify.com/v1/search"
data = urlencode({"q":"the daily","type":"show"})
# data = urlencode({"q":"drake","type":"artist"})
lookup_url = f"{endpoint}?{data}"
print(lookup_url)
r = requests.get(lookup_url, headers=headers)
print(r.status_code)
r.json()
获取上面显示的输出为:
https://api.spotify.com/v1/search?q=the+daily&type=show
200
{'shows': {'href': 'https://api.spotify.com/v1/search?query=the+daily&type=show&offset=0&limit=20',
'items': [None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None,
None],
'limit': 20,
'next': 'https://api.spotify.com/v1/search?query=the+daily&type=show&offset=20&limit=20',
'offset': 0,
'previous': None,
'total': 14755}}
如果我尝试搜索艺术家的信息,我会得到很好的结果:
{'artists': {'href': 'https://api.spotify.com/v1/search?query=drake&type=artist&offset=0&limit=20',
'items': [{'external_urls': {'spotify': 'https://open.spotify.com/artist/3TVXtAsR1Inumwj472S9r4'},
'followers': {'href': None, 'total': 48844145},
'genres': ['canadian hip hop',
'canadian pop',
'hip hop',
'pop rap',
'rap',
'toronto rap'],
'href': 'https://api.spotify.com/v1/artists/3TVXtAsR1Inumwj472S9r4',
'id': '3TVXtAsR1Inumwj472S9r4',
'images': [{'height': 640,
'url': 'https://i.scdn.co/image/60cfab40c6bb160a1906be45276829d430058005',
'width': 640},
{'height': 320,
'url': 'https://i.scdn.co/image/5ea794cf832550943d5f8122afcf5f23ee9d85b7',
'width': 320},
{'height': 160,
'url': 'https://i.scdn.co/image/8eaace74aaca82eaccde400bbcab2653b9cf86e1',
'width': 160}],
'name': 'Drake',
'popularity': 98,
'type': 'artist',
'uri': 'spotify:artist:3TVXtAsR1Inumwj472S9r4'},
...output clipped for readability
3。问题:
- 我是否试图错误地提取有关节目的信息?我尝试使用下面提到的搜索端点 - 这似乎适用于艺术家或曲目,但不适用于节目。
- 是否可以获取节目的指标 - 例如关注者、times_episodes_played 和历史数据?
感谢您的帮助。
【问题讨论】:
-
在发帖之前,我已投票赞成展示重要的研究工作。但是,请考虑根据 Stack Overflow 的 How to Ask 指南编辑您的问题以专注于单个查询。为了回答您的第二个问题,the documentation 显示您要求的那些属性在您使用的 API 端点中不可用。我想数据会非常接近,因为它会影响广告收入等。
-
好的,感谢您的指导。我同意“times_episodes_played”指标。这可能不可行。但是追随者应该是可行的,对于艺术家来说已经得到了。此外,在再次尝试文档后,我发现了一些有趣的东西。如果您尝试使用“Show id”和“OAuth Token”和 Market 为空白的“Try It - Example Request”here,您会收到我之前看到的“non-existing id”错误。但是,如果您进入一个随机市场(这是可选的),它会起作用!也适用于搜索端点
-
market参数确实记录为 可选 - 您可能希望向他们在链接页面上列出的电子邮件发送消息以提交错误报告或让他们获得额外的支持。 -
确实,market 并不像文档所说的那样可选,因为我也发现 Podcast Shows 和 Episode 端点存在同样的问题,但是文档的某些部分确实提到了 Market 需要获取它们如果在不同的 API 调用文档中看不到这一点,那么有点不清楚
标签: python python-3.x api python-requests spotify