- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
My auth code to get auth token:
const requestAuthToken = async () => {
await fetch("https://accounts.spotify.com/api/token",
{ body: `grant_type=client_credentials&client_id=${CLIENT_ID}&client_secret=${CLIENT_SECRET}`,
headers: { "Content-Type": "application/x-www-form-urlencoded", },
method: "POST", })
.then((response) => response.json())
.then((data) => { setAuthToken(data.access_token);
navigate("/home");
}) };
This is code that fetchs data from /me api:
const getUserData = async (token: string) => {
await fetch("https://api.spotify.com/v1/me",
{ headers: { Authorization: "Bearer " + token, } })
.then((response) => response.json())
.then((data) => {
console.log(data);
setUser(User.fromJSON(data)); })
.catch((error) => { console.log(error); }); }
The auth function is working so I can get the auth token and save it. But when I try to get users data it is returning 401 Unauthorized.
Why?
Solved! Go to Solution.
- Labels:
-
Web API
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page