Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

268
Vistas
{ error: 'invalid_client' } while using Spotify's API

Error gives 'invalid client' and Bad Request. Cross-checked headers, can't find the cause of the error. Encountered this while implementing Spotify's Authorization Code Flow.

The header of this post must contain Authorization as a parameter

Base 64 encoded string that contains the client ID and client secret key. The field must have the format: Authorization:<base64 encoded client_id:client_secret>

app.get('/callback', (req, res) => {
        const code = req.query.code || null;
        const state = req.query.state || null;
        const storedState = req.cookies ? req.cookies[stateKey] : null;
    
    axios({
                method: 'post',
                url: 'https://accounts.spotify.com/api/token',
                data: queryString.stringify({
                    grant_type: 'authorization_code',
                    code: code,
                    redirect_uri: REDIRECT_URI
                }),
                headers: {
                    'content-type': 'application/x-www-form-urlencoded',
                    Authorization: `Basic ${new Buffer.from(`${CLIENT_ID}:${CLIENT_SECRET}`.toString('base64'))}`
                },
                json: true
            })
                .then(response => {
                    if (response.status === 200) {
        
                        const { access_token, token_type } = response.data;
                        console.log(response.data)
        
                        axios.get('https://api.spotify.com/v1/me', {
                            headers: {
                                Authorization: `${token_type} ${access_token}`
                            }
                        })
                            .then(response => {
                                res.send(`<pre>${JSON.stringify(response.data, null, 2)}</pre>`);
                            })
                            .catch(error => {
                                res.send(error)
                            })
                    } else { res.send(response) }
                })
                .catch(error => {
                    // res.send(err)
                    if (error.response) {
                        console.log(error.response.data)
                        res.send(error)
                    }
                });
        
       

})

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda