Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
{ 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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda