Twitch Project Questions- manipulating data

Twitch Project Questions- manipulating data
0.0 0

#1

I have gotten the data from the api. as far as i can tell i have 8 different objects. if this was an array i think i could get at the data no problem. but im stumped. ive been researching for a while now. i m wondering if my entire approach is wrong. everything i try goes nowhere good. any tips id appreciate. thanks

link - http://codepen.io/benjaminadk/pen/jmYOMJ?editors=1111


#2

Hey there … It seems that you call is actually correct, as it returns the data from the getJSON method. I would suggest that you first get everything working for a single user, before looping through all users as the amount of data can be confusing at first.

The /users/ call is usefull only to determine if a player is currently streaming(what i did was use this as an indicator to check if a player exists) and then, make another call to the API using the /streams endpoint.

Currently, you would be able to get that info by logging data.stream, for example. Remember that the information you get is an Object , so you would access the information as you would any other object, be it dot or bracket notation. Hope this helps, but if you are still struggling, drop me a msg and i’ll happily help you out.

Happy coding!


#3
  $(document).ready(function(){
      var users = ["ESL_SC2", "OgamingSC2", "cretetion", "freecodecamp", "storbeck", "habathcx", "RobotCaleb", "noobs2ninjas"];
      for(var i=0; i<users.length; i++){
        $.ajax({
          method : 'GET',
          url: 'https://wind-bow.glitch.me/twitch-api/users/' + users[i] + '?callback=?',
          dataType: 'json',
          success: function(data){
            $('#bios').append('<li>' + data.name + ', ' + data.bio + '</li>');
          }
        });
      }      
    });

    And HTML : 

    <h1>Users</h1>
    <ul id='bios'>
</ul>

#4

You can see that you are actually getting data back. Now you need to extract from that object what you need from information. The JSON object returned is :slight_smile:

{“display_name”:“FreeCodeCamp”,"_id":79776140,“name”:“freecodecamp”,“type”:“user”,“bio”:“We help you learn to code, then practice by building projects for nonprofits. Learn Full-stack JavaScript, build a portfolio, and get a coding job by joining our open source community at https://freecodecamp.com”,“created_at”:“2015-01-14T03:36:47Z”,“updated_at”:“2017-05-08T17:02:32Z”,“logo”:“https://static-cdn.jtvnw.net/jtv_user_pictures/freecodecamp-profile_image-d9514f2df0962329-300x300.png","_links":{“self”:"https://api.twitch.tv/kraken/users/freecodecamp”}}

That is for single user, now you do it in a loop so each user you process in success() function. Hope that helps.