using async module in nodejs returns nothing in response

62 Views Asked by At

I'm trying to post to Instagram API to authenticate user, but I'm getting null value as response. Before using async, I used setTimeout but it returned the error you must provide a client_id. This is my previous post regarding the error.
Here is my code:

app.get('/home',function(req,res){
  req.session.code = req.query.code;
  var data = querystring.stringify({
      client_id: process.env.CLIENT_ID,
      client_secret: process.env.CLIENT_SECRET,
      grant_type: "authorizaton_code",
      redirect_uri: "...",
      code: req.session.code
  })
  var options = {
    headers:{
      'content-type': 'application/x-www-form-urlencoded'
    },
      hostname: 'api.instagram.com',
      path: '/oauth/access_token',
      method:'POST',
      port:443
    }
    req.session.data = '';
    async.waterfall([
      function(callback){
        var request = https.request(options,function(resp){
          resp.on('data',function(chunk){
            req.session.data = chunk.toString();
          })
        })
        request.write(data);
        request.end();
        callback(null,req.session.data);
      }
     ],function(err,results){
      res.json(req.session.data||results[0]);
     })
})
0

There are 0 best solutions below