- nodejs 18.0 (or later)
- js-controller 5.0.0 (or later)
- Admin Adapter 6.0.0 (or later)
To get an API-Key you have to go to console.developers.google.com.
- Create a new Project
- Create a new API key
- Add "YouTube Data API v3" of the library
- Use that API-Key in the instance configuration
- Add multiple channels in the channels tab by using the id and a custom name
on({ id: 'youtube.0.summary.json', change: 'any' }, async (obj) => {
try {
const youtubeJson = obj.state.val;
const channels = JSON.parse(youtubeJson);
const ts = Date.now();
for (const channel of channels) {
const alias = channel.customUrl.substr(1); // remove leading @
await this.sendToAsync('influxdb.0', 'storeState', {
id: `youtube.0.channels.${alias}.subscribers`,
state: {
ts,
val: channel.subscriberCount,
ack: true,
from: `system.adapter.javascript.0.${scriptName}`,
}
});
await this.sendToAsync('influxdb.0', 'storeState', {
id: `youtube.0.channels.${alias}.views`,
state: {
ts,
val: channel.viewCount,
ack: true,
from: `system.adapter.javascript.0.${scriptName}`,
}
});
}
} catch (err) {
console.error(err);
}
});