对 Spotify API 的请求返回 403

时间:2021-04-12 10:55:38

标签: reactjs axios spotify

我使用 Axios 在 Spotify api 中放置了一个 post 请求。

但是 403 是从 spotify api 返回的,我不知道为什么。

 const App = () => {
    const buttonClick = () => {
        const token = sessionStorage.getItem('token');
        const user_id = sessionStorage.getItem('userId');
    
        axios({
            headers: {
                "Authorization": `Bearer ${token}`,
            }, method: 'POST',
            url: `https://api.spotify.com/v1/users/${user_id}/playlists`,
            data: {
                name: "내플레이리스트",
                public: true,
                collaborative: false,
                description: "안녕하세요 반가워요 저리가세요"
           },
        }).then((res) => {
            console.log(res);

        }).catch(error => {
            console.log(error);
        });
    }

    return(
        <div>
             <button onClick={buttonClick}>hi</button>
        </div>
    );
}

0 个答案:

没有答案