This is a NodeCG bundle.
Lets other bundles easily query the Twitch API on behalf of a logged in user. Requires Twitch authentication to be enabled in your NodeCG installation.
- Install to
nodecg/bundles/lfg-twitchapi
- Create
nodecg/cfg/lfg-twitchapi.json
with a valid configuration (see below).
{
"username": "langeh"
}
First, ensure that your NodeCG installation is using Twitch authentication. See the NodeCG configuration docs for details.
Then, add lfg-twitchapi
as a bundleDependency
in your bundle's nodecg.json
Now, add the following code to your bundle's extension:
var twitchApi = nodecg.extensions['lfg-twitchapi'];
// Gets the 25 most recent subs
// {{username}} will be automatically replaced by the username specified in lfg-twitchapi.json
twitchApi.get('/channels/{{username}}/subscriptions', { limit: 25, direction: 'desc' },
function(err, code, body) {
if (err) {
nodecg.log.error(err);
return;
}
if (code !== 200) {
nodecg.log.error(body.error, body.message);
return;
}
// Go through subs in reverse, from oldest to newest
body.subscriptions.reverse().forEach(function(subscription) {
var username = subscription.user.name;
var channel = body.channel;
console.log('%s subscribed to channel %s', username, channel);
});
});
Makes a call to the Twitch API, invoking callback
with the response.
If {{username}}
is present in path
, it will be replaced with the value of nodecg.bundleConfig.username
.
path
is the desired endpoint; ex:/channels/{{username}}/subscriptions
options
is an object of query parameters; ex:{ limit: 25, direction: 'desc' }
callback
will be invoked with the response from the Twitch API
lfg-twitchapi is provided under the MIT license, which is available to read in the [LICENSE][] file. [license]: LICENSE