401 Error with seemingly working access token
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using the following code to get an access token, and the final post request returns a status code of 200 and when I print out the access token it looks good. However as soon as I try to use the access token I get a 401 Unauthroized error. I have been slamming my head against the wall looking everywhere for what I am doing wrong and can't find it, please let me know if you have any tips.
app.get('/spotifylogin', function(req, res) {
let url = AUTHORIZE;
url += "?client_id=" + client_id;
url += "&response_type=code";
url += "&redirect_uri=" + redirect_uri;
url += "&show_dialog=true";
url += "&scope=user-top-read";
res.redirect(url); // Show Spotify's authorization screen
});
app.get('/callback', function(req, res) {
const authConfig = {
headers: {
Authorization: `Basic ${Buffer.from(
`${client_id}:${client_secret}`
).toString('base64')}`,
}
};
axios.post(
'grant_type=client_credentials',
authConfig
).then(data => {
access_token = data.data.access_token;
//refresh_token = data.refresh_token;
//localStorage.setItem('refresh_token',refresh_token);
spotify_linked = true;
res.redirect('/toptracks');
})
.catch(error => {
console.log(error);
})
});
This is the function I am calling with the access token which gives me the 401 error.
This is the function I am calling with the access token which gives me the 401 error.
async function getProfile(accessToken) {
headers: {
Authorization: 'Bearer ' + accessToken
}
});
const data = await response.json();
console.log(data);
}
Labels:
- Labels:
-
API Help
-
API Question
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page