简体   繁体   English

通过 Spotify API 从播放列表中获取 ID

[英]Getting ID's from playlist through Spotify API

My problem is that I can not figure out a way to get the playlist ID or the track ID.我的问题是我无法找到获取播放列表 ID 或曲目 ID 的方法。 Here is a snipped of the code.这是代码的片段。 The json_response is correct I am just going about parsing through it very wrong. json_response 是正确的,我只是想解析它非常错误。 I have changed my code around from trying to get a playlist ID to trying to get a song id, here currently I am trying to get a track id.我已将代码从尝试获取播放列表 ID 更改为尝试获取歌曲 ID,目前我正在尝试获取曲目 ID。 But before I had code trying to get the playlist ID and I was working through the son wrong as well.但在我尝试获取播放列表 ID 的代码之前,我也在处理儿子的错误。

token = getAccessToken(clientID, clientSecret)
response =requests.get(query,
headers={"Content-Type":"application/json",
            "Authorization":"Bearer " + token})
    
json_response = response.json()
head_one = "<h1/>"
head_two = "</h2"
id = json_response.id
return id

Perhaps you could try this syntax也许你可以试试这个语法

#...

id = json_response["id"]
return id

If that does not work I suspect you still need to convert to JSON yourself如果这不起作用,我怀疑您仍然需要自己转换为 JSON

import json

#...
json_response = json.loads(response.json)
id = json_response["id"]
return id

Please let me know if it works请让我知道它是否有效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM