Spotify API从自己的Spotify数据获取TRACK_URI或TRACK_ID

发布于 2025-01-28 15:55:03 字数 1455 浏览 2 评论 0原文

[在此处输入图像描述] [1]我有一个数据框架,其中包括我自己从Spotify(https://www.spotify.com/de/account/privacy/)请求的数据,我有.json数据,我已经转换为.csv,那是我的流史(包括MSPlay,时间戳,艺术家,脚部名称)。我想将TRACK_ID或URI添加到数据框架中。这对于曲目名称和ArtistName与Spotify API的匹配有可能吗?因为API现在对我来说很复杂。

现在,我想添加一个带有URI/TRACK_ID的新列,然后获得歌曲的音频功能。正如我已经说过的那样,我不知道是否有可能以这种方式获得URI。 [1]: https://i.sstatic.net/s2ugh.png

CLIENT_ID = '' 
CLIENT_SECRET = ''

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

AUTH_URL ="https://accounts.spotify.com/api/token"
auth_response = requests.post(AUTH_URL, {
    'grant_type': 'client_credentials',
    'client_id': CLIENT_ID,
    'client_secret': CLIENT_SECRET,
})

#Convert response to JSON
auth_response_data = auth_response.json()

#Save the access token
access_token = auth_response_data['access_token']

#Need to pass access token into header to send properly formed GET request to API server
headers = {
    'Authorization': 'Bearer {token}'.format(token=access_token)
}
sp=spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id="CLIENT_ID",client_secret="CLIENT_SECRET"))

BASE_URL = 'https://api.spotify.com/v1/'




df.to_csv(StreamingHistoryEditedComplete.csv)

new_df['songArtistID'] = new_df['artistName'] + ":" + new_df['trackName']


[enter image description here][1]I have a dataframe that included my own data I've requested from Spotify (https://www.spotify.com/de/account/privacy/) Now, I have .json data, that I've converted to .csv, that is my StreamingHistory ( incl msplayed, timestamp, artist, trackName). I'd like to add the track_id or uri to the dataframe. Is that possible to a match of the trackName and artistName with the Spotify API? Because the API is kind of complex for me now.

Now I'd like to add a new column with the uri/track_id to then get the audio features of the song. As I've said already I don't know if it's possible to get the uri in this way.
[1]: https://i.sstatic.net/S2UGh.png

CLIENT_ID = '' 
CLIENT_SECRET = ''

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

AUTH_URL ="https://accounts.spotify.com/api/token"
auth_response = requests.post(AUTH_URL, {
    'grant_type': 'client_credentials',
    'client_id': CLIENT_ID,
    'client_secret': CLIENT_SECRET,
})

#Convert response to JSON
auth_response_data = auth_response.json()

#Save the access token
access_token = auth_response_data['access_token']

#Need to pass access token into header to send properly formed GET request to API server
headers = {
    'Authorization': 'Bearer {token}'.format(token=access_token)
}
sp=spotipy.Spotify(auth_manager=SpotifyClientCredentials(client_id="CLIENT_ID",client_secret="CLIENT_SECRET"))

BASE_URL = 'https://api.spotify.com/v1/'




df.to_csv(StreamingHistoryEditedComplete.csv)

new_df['songArtistID'] = new_df['artistName'] + ":" + new_df['trackName']


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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文