Instantly share code, notes, and snippets.

anonymous /test.js
Created Feb 13, 2016

Embed
What would you like to do?
var fs = require("fs");
var https = require("https");
var bearer = "pXZ8xSWvjZjE4UaNntVsCwWPg:ziSswccgj8xm7TGrJ0GcEoVl2tgPaMiNYOWzQeDIhpFTJIMSro"
var base64ed = new Buffer(bearer).toString("base64");
var options = {
port: 443,
hostname: "api.twitter.com",
// path: "/1.1/search/tweets.json?" + encodeURIComponent("q='social media'"),
path: "/oauth2/token",
method: "post",
key: fs.readFileSync("./testssl.key"),
cert: fs.readFileSync("./testcert.cert"),
// headers: {
// "content-type": "application/x-www-form-urlencoded;charset=UTF-8"
//
// },
auth: base64ed + '"content-type": "application/x-www-form-urlencoded;charset=UTF-8"'
}
var req = https.request(options, res => {
console.log(res.req._header);
res.on("data", d => {
console.log(d.toString());
})
})
req.on("error", e => {
console.log(e);
});
req.write("grant_type=client_credentials");
req.end();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment