icalvete
icalvete

Reputation: 1159

Pubsubhubbub subscription error: "Challenge mismatch."

I'm trying to get push content from a youtube channel as I read https://developers.google.com/youtube/v3/guides/push_notifications

I read http://pubsubhubbub.github.io/PubSubHubbub/pubsubhubbub-core-0.4.html and amny other documents aswell

I have wrote this easy nodojs program.

const express     = require('express');
const bodyParser  = require('body-parser');
const axios       = require('axios')
const cp          = require('child_process');
const shell       = require('shelljs');
require('body-parser-xml')(bodyParser);

const app         = express();

app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({extended: true})); // for parsing application/x-www-form-urlencoded
app.use(bodyParser.xml({
    limit:'25MB'
}));


app.get('/', function(req, res) {
        console.log('GET')
        console.log(req.protocol)     // "https"
        console.log(req.hostname)     // "example.com"
        console.log(req.path)         // "/creatures"
        console.log(req.originalUrl)  // "/creatures?filter=sharks"
        console.log(req.subdomains)   // "['ocean']


        hub_challenge = req.query['hub.challenge']
        console.log('---------------------------------------')
        console.log(req.query)
        console.log(req.body)
        console.log('---------------------------------------')

        if (hub_challenge) {
                res.status(204).end(hub_challenge)
        }
});


app.post('/', function(req, res) {
        console.log('POST')
        console.log(req.protocol)     // "https"
        console.log(req.hostname)     // "example.com"
        console.log(req.path)         // "/creatures"
        console.log(req.originalUrl)  // "/creatures?filter=sharks"
        console.log(req.subdomains)   // "['ocean']

        const body    = req.body
        var message = undefined

        if (body.hasOwnProperty('message')) {
                message = req.body.message
        } else if (body.hasOwnProperty('edited_message')) {
                message = req.body.edited_message
        }

        console.log('---------------------------------------')
        console.log(req.body)
        console.log('---------------------------------------')

        res.header('Cache-Control', 'private, no-cache, no-store, must-revalidate');
        res.header('Expires', '-1');
        res.header('Pragma', 'no-cache');

        if (hub_challenge) {
                res.status(204).end()
        }
});


// Finally, start our server
app.listen(1111, function() {
        console.log('App listening on port 1111!')
});

I used https://pubsubhubbub.appspot.com/subscribe (Subscribe/Unsubscribe Section) to lauch a subscription. pubsubhubbub reach my server and I just print hub.challenge and return an 204 HTTP Status code.

GET
http
ec2-xxx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com
/
/?hub.topic=https://www.youtube.com/xml/feeds/videos.xml%3Fchannel_id%3DUCLzgGM7q2bXebJUs7cymdhg&hub.challenge=2167537649875952601&hub.mode=subscribe&hub.lease_seconds=432000
[ 'compute', 'eu-west-1', 'ec2-xxx-xxx-xxx-xxx' ]
---------------------------------------
{}
{
  'hub.topic': 'https://www.youtube.com/xml/feeds/videos.xml?channel_id=UCLzgGM7q2bXebJUs7cymdhg',
  'hub.challenge': '2167537649875952601',
  'hub.mode': 'subscribe',
  'hub.lease_seconds': '432000'
}
#2167537649875952601#
---------------------------------------

Since I used Verify Type = sync, pubsubhubbub return the verification inmediatly with the message Challenge mismatch.

I used https://pubsubhubbub.appspot.com/subscribe (Subscriber Diagnostics Section) to debug but my subscription remain unverified

What I'am doing wrong?

Upvotes: 0

Views: 287

Answers (1)

aldin
aldin

Reputation: 1

When you send back hub_challenge, try the following. It works for me.

res.set('Content-Type', 'text/plain');
res.status(200).send(hub_challenge);

Upvotes: 0

Related Questions