Example of getting subscriber count and follower count through JS SDK?

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.

I think you want to take a look at this page for pulling subscription data and this page for auto following a subbed channel.

The last page is some topic i created because i’m quite new to working with api’s myself and i was having some trouble with a follow button. This code could help you achieve auto following a subbed channel. Make sure you don’t make the same mistake tho :wink:

Thanks Webbie. I’ll take a look at the code and see if it clears up my confusion. Appreciate you helping out!

just helping a fellow countrymen out just like Fugiman (thnx bro) helped me out! If you need anything else, i’ll be watching this topic.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.