首页 > 解决方案 > 在 Spotify 上获取当前播放的歌曲

问题描述

我正在尝试使用 Python 在 Spotify 上获取当前播放的歌曲:

def get_currently_played_song():
    response = requests.post(
        'https://accounts.spotify.com/api/token',
        data={
            'grant_type': 'client_credentials'
        },
        auth=(SPOTIFY_CLIENT_ID, SPOTIFY_CLIENT_SECRET)
    )
    access_token = response.json()['access_token']
    current_song = requests.get(
        'https://api.spotify.com/v1/me/player/currently-playing',
        headers={
            'Authorization': f'Bearer {access_token}'
        }
    )
    print(current_song)

但是,我得到了 404。我认为端点是错误的,但我不确定是否应该替换 URL 中的某些内容。我尝试用我的 Spotify 用户名替换“我”,但问题仍然存在。

标签: pythonspotify

解决方案


推荐阅读