Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

161
Views
Twitch POST request for OAuth2 token

I'm trying to get an access token via a POST request from the Twitch API but my http.request is never executing (I don't think) and I can't figure out why.

var express               = require('express');
var path                  = require('path');
var bodyParser            = require('body-parser');
var fs                    = require('fs');
var https                 = require('https');
var querystring           = require('querystring');
var authInfo              = require('./authInfo.json');

app.get('/twitch/auth', function(req, res) {
  res.send("auth page");

  var data = querystring.stringify({
    client_id: authInfo.clientID,
    client_secret: authInfo.clientSecret,
    grant_type: "authorization_code",
    redirect_uri: authInfo.redirectURI,
    code: req.query.code,
    state: 12345
  });

  var options = {
    host: 'api.twitch.tv',
    port: 443,
    path: '/kraken/oauth2/token',
    method: 'POST',
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
      'Content-Length': Buffer.byteLength(data)
    }
  }

  var req = https.request(options, (res) => {
    console.log('statusCode:', res.statusCode);
    console.log('headers:', res.headers);

    res.on('data', (d) => {
      console.log(d);
    });
  });

  req.on('error', (e) => {
    console.log(e);
  });

  req.end();

});

app.listen(port, function() {
  console.log('Point browser to: http://localhost:' + port);
});

PS I've omitted the some code for brevity but I get back an authorization code successfully.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

I solved my problem. I wasn't writing data to the body.

...
  req.write(data);
  req.end();

});
...
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!