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

130
Visualizações
Why is my response object empty using Express.js?

I am trying to authenticate Spotify API using the OAuth2.0 client credentials flow. Generally the flow is as follows:

  1. Send GET request to /authenticate endpoint with required parameters, including a callback endpoint that i have set to my http://localhost:8888/callback
const open = require('open')

responseType = 'token'
clientID = 'CLIENT_ID'
redirectURI = 'http%3A%2F%2Flocalhost%3A8888%2Fcallback'
scope = 'streaming+user-read-email+user-modify-playback-state+user-read-private+user-library-read+user-library-modify+user-read-currently-playing'
contentType = 'application/json'

params = {
  'response_type' : responseType,
  'client_id' : clientID,
  'redirect_uri' : redirectURI,
  'scope' : scope
}

headers = {
  'Content-Type' : contentType
}

// send user to browser to grant data permissions
open(`https://accounts.spotify.com/en/authorize?response_type=${responseType}&client_id=${clientID}&redirect_uri=${redirectURI}&scope=${scope}&show_dialog=true`)

-- this part is fine, i have no issues sending user to browser to login and grant my app permission and the Express server i have listening on port 8888 lets me know when the callback pings with the response

  1. Receive Authentication Token in params of callback from Authentication endpoint. Spotify API handles this part and sends the authentication token that i need as part of the header in the response. it looks like this http://localhost:8888/callback#authentication_token=2iais820zg...fh9IHkLDI&timeout=3600 -- this is what i am having problems with.

here is my how i am handling the api callback in my Express server's /callback endpoint:

app.get('/callback', function (req, res) {
    console.log('someone made a request!\n')
    ///                             ////
    console.log(req + '\n')
    console.log(res + '\n')
    ///                             ////
    console.log(req.body)
    res.json(req.body)
    res.send('GET request to callback endpoint took you here')
    res.end()
})

but the console output is as follows:

> server is listening on port 8888 ...
someone made a request!

[object Object]

[object Object]

{}

where everything is empty.

how can i access the URL parameters of the callback GET request? i have tried changing the handling from GET to POST as people have told me that a GET request doesn't contain params but the callback can't find the endpoint (bc it's not making a POST request..)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

you should put the parameters into request body not in the header as you mentioned to let you use req.body with no problem

about 4 years ago · Juan Pablo Isaza Relatório
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