Hey guys,
Thanks for the great work. Fairly new to working with APIs. I’m trying to build a simple app called SubFollow.com to retrieve a user’s subscriber list and follow those subs.
I’m playing around with the example app (http://justintv.github.io/twitch-js-sdk/example.html) and I’m running into problems formatting the Javascript Twitch.api calls. I was wondering if you could give some examples of how you’d write the code to pull subscription totals and streams followed, similar to what you did in the example app.
Here’s what I’m trying to get to work:
// straight from the example app... works fine.
$('#get-name button').click(function() {
Twitch.api({method: 'user'}, function(error, user) {
$('#get-name input').val(user.display_name);
});
})
// also straight from example app... works fine.
$('#get-stream-key button').click(function() {
Twitch.api({method: 'channel'}, function(error, channel) {
$('#get-stream-key input').val(channel.stream_key);
});
})
// Not sure what I'm supposed to use in the method, function, or val parts... broken code.
$('#get-sub-count button').click(function() {
Twitch.api({method: '/channels/:channel/subscriptions'}, function(error, subscriptions) {
$('#get-sub-count input').val(subscriptions._total);
});
})
// This one I got working, but it's from the same endpoint as examples so not too easy to break.
$('#get-follow-count button').click(function() {
Twitch.api({method: 'channel'}, function(error, channel) {
$('#get-follow-count input').val(channel.followers);
});
})
// Took some shots in the dark and tried sticking with channel in the function and val... still broken.
$('#get-streams-followed button').click(function() {
Twitch.api({method: 'streams/followed'}, function(error, channel) {
$('#get-streams_followed input').val(channel._total);
});
})
Thanks for the help.