Hello, I’m trying to get my webhook working.
I’m using NodeJS with an express app and twitter module.
Here’s my error: [ { code: 214,
2018-10-16T16:58:33.654558+00:00 app[web.1]: message: ‘Webhook URL does not meet the requirements. Please use HTTPS.’ } ]
When printing out res.statusCode inside createWebhook function I get: statusCode 400
Here’s my code:
APP.JS
app.get('/webhook/twitter', (req, res) => {
var crc_token = req.query.crc_token;
console.log(crc_token);
if (crc_token) {
var hash = security.get_challenge_response(crc_token, twitt.twitter.consumer_secret);
console.log(hash);
res.status(200); // STATUS OK
res.send(
{
response_token: 'sha256=' + hash
}
);
} else {
res.status(400); // STATUS BAD REQUEST
res.send('Error: crc_token missing from request.');
}
});
SECURITY JS
const crypto = require('crypto');
/**
* Creates a HMAC SHA-256 hash created from the app TOKEN and
* your app Consumer Secret.
* @param token the token provided by the incoming GET request
* @return string
*/
module.exports.get_challenge_response = function(crc_token, consumer_secret) {
hmac = crypto.createHmac('sha256', consumer_secret).update(crc_token).digest('base64');
return hmac;
}
twitt.js
function getWebhook() {
console.log("Getting webhook");
twitter.get('account_activity/all/Development/webhooks', (err, res, body) => {
if (err) throw err;
console.log(body);
});
}
function createWebhook(url) {
console.log("Creating webhook");
urls = { url: url };
twitter.post('account_activity/all/Development/webhooks', urls, (err, body, res) => {
console.log(body);
console.log("statusCode " + res.statusCode)
if (res) getWebhook();
});
}
And then I call createWebhook(‘https%3A%2F%2Funimitwitterbot.herokuapp.com%2Fwebhook%2Ftwitter’);