'listen to youtube api notification
when live video started on youtube channel , i want to know it and send to apple APN server. it' possible? I am ios developer and I am new on node.js. I wrote these code for listen youtube
const YouTubeNotifier = require('youtube-notification');
const notifier = new YouTubeNotifier({
hubCallback: 'https://youtube-server-i2ntcu76bq-uc.a.run.app/youtube/callback',
port: 8080,
path: '/youtube'
});
notifier.setup();
notifier.on('notified', data => {
console.log('New Video');
console.log(
`${data.channel.name} just uploaded a new video titled: ${data.video.title}`
);
});
notifier.subscribe('UC1zAttFQKikWoKH3Vb39ETA');
My callback is :
https://youtube-server-i2ntcu76bq-uc.a.run.app/youtube/callback
const express = require('express');
const app = express();
const axios = require("axios");
const apiUrl = "https://www.googleapis.com/youtube/v3";
const apiKey = "API_KEY_GOES_HERE";
const channelId = "UC1zAttFQKikWoKH3Vb39ETA";
// get an instance of router
var router = express.Router();
//https://youtube.googleapis.com/youtube/v3/search?channelId=UC1zAttFQKikWoKH3Vb39ETA&key=AIzaSyAnY52Lr-hOku3fdxVQLIbm45TpZbDWzvw
// home page route (http://localhost:8080)
router.get('/', function(req, res) {
res.send('im the home page!');
});
router.get('/youtube/callback', (req, res) => {
//console.log('here', req.body, req.query, req.params, req.headers)
console.log('here', res.body)
let query = req.query
if('hub.challenge' in query){
let channelID = query['hub.topic'].split('=').pop()
/*if(!bot.youtube.pendingVerify.has(channelID)) {
console.log('Invalid youtube hook sent to me', channelID, req.headers)
return res.sendStatus(401)
}*/
/* bot.youtube.lease.set(channelID, Date.now() + (query['hub.lease_seconds'] * 1000))
bot.youtube.pendingVerify.delete(channelID)*/
//return res.status(202).send(query['hub.challenge'])
//const responseText = req.query['hub.challenge'] || "no challenge"
// res.send(responseText)
}
return req.query['hub.challenge']
})
router.post('/youtube/callback', (req, res) => {
console.log('here', res.body)
//console.log('here post', req.body, req.query, req.params, req.headers)
return req.query['hub.challenge']
// let hmac = generateHMAC(req.query['hub.challenge'], 'very_secret', "sha1")
})
/*
function generateHMAC(hmac, secret, algo = 'sha256'){
return `${algo}=${crypto.createHmac(algo, secret).update(hmac).digest('hex')}`
}
*/
// apply the routes to our application
app.use('/', router);
// Start the server
const PORT = process.env.PORT || 8080;
app.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
console.log('Press Ctrl+C to quit.');
});
when i add video or live video on youtube ,notifier.on('notified', data ) not work. why i can't listen youtube and i have log on google cloud that :
FeedFetcher-Google; (+http://www.google.com/feedfetcher.html) https://youtube-server-i2ntcu76bq-uc.a.run.app/youtube/callback?hub.topic=https://www.youtube.com/xml/feeds/videos.xml%3Fchannel_id%3DUC1zAttFQKikWoKH3Vb39ETA&hub.challenge=5437060724976338936&hub.mode=subscribe&hub.lease_seconds=432000 The request has been terminated because it has reached the maximum request timeout. To change this limit, see https://cloud.google.com/run/docs/configuring/request-timeout
how can i listen youtube ? please help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
