Help Wizard

Step 1

NEXT STEP

FAQs

Please see below the most popular frequently asked questions.

Loading article...

Loading faqs...

VIEW ALL

Ongoing Issues

Please see below the current ongoing issues which are under investigation.

Loading issue...

Loading ongoing issues...

VIEW ALL

Track not being fetched - 404 error

Track not being fetched - 404 error

Daf25

Plan

Premium

Country

Argentina

Device

(iPhone 8, Samsung Galaxy 9, Macbook Pro late 2016)

Operating System

Windows 10

 

My Question or Issue

I'm trying to make a GET request to the Spotify Web API for a track using simple JavaScript (I don't know curl), but it's giving me a 404 error

My code:

//async function to get the token
const getToken = async() => {
    const result = await fetch('https://accounts.spotify.com/api/token', {
    method: 'POST',
    body: 'grant_type=client_credentials',
    headers: {
        'Authorization': 'Basic ' + Buffer.from(clientID + ':' + clientSecret).toString('base64'),
        'Content-Type': 'application/x-www-form-urlencoded'
    }
    })
    const data = await result.json();
    const realToken = data.access_token;
    return realToken;
   
}
getToken().then((token) => {
    //async function to get songs
const getTracks = async(whatever) => {
    const result = await fetch('https://api.spotify.com/v1/track/6ydEhrdfzhI29D2NBAqUY1', {
        method: 'GET',
        headers: {
        'Authorization': 'Bearer ' + whatever,
        'Content-Type': 'application/json'
    }
    });
    const data = await result.json();
    return data;
}
getTracks(token);

});

 

 

Reply
0 Replies

Suggested posts