Searched everywhere online with no luck and now I'm at the edge. I have created an application that gets a live subscriber count for the top 50 channels in the world. My code works fine but seems there is no increase or decrease in the subscriber count. The subscriber count from API remained the same even after setting the time interval or even refreshing the googleapis JSON result page. No increase or anything, subscribers count was static.
I'm looking for a solution like this: https://www.youtube.com/watch?v=ftMnmPC82qM&ab_channel=MDM
Mind you, the same channels those guys on the above youtube video are showing are the same channels I'm showing, but theirs seems to increase count but mine never increases.
this is my code
function get_json_data( object, should_load_silently = false ){ ////console.log( get_url( object ) ); if( !should_load_silently ){ $( '.loading-holder' ).show(); } var previous_data = {}; var new_count_object = {}; var the_previous_data_object_string = JSON.parse( localStorage.getItem( 'previous_data' ) ); var parsed_new_count = JSON.parse( localStorage.getItem( 'new_count' ) ); //console.log( localStorage.getItem( 'previous_data' ) +'\n\n\n' ) $.getJSON( get_url( object ), function( data ){ var object_keys = Object.keys( object ); for ( var i = 0; i < data.items.length; i ++ ) { //console.log( get_increase( 1, 1000 ) +'\n'); $( '.loading-holder' ).hide(); var channel_id = data.items[i].id; if( parseInt( get_new_count( channel_id, parsed_new_count ) ) == 0 ){ var sub_count = Number( data.items[i].statistics.subscriberCount ) + parseInt( get_increase(1, 200) ); new_count_object[channel_id] = sub_count; } else { var sub_count = parseInt( get_new_count( channel_id, parsed_new_count ) ) + parseInt( get_increase(1, 200) ); new_count_object[channel_id] = sub_count; } var target_class = $( '.sub-count-item' )[i]; $( '#'+channel_id ).find( '.total-count num' ).html( sub_count ); ////console.log( object_keys[i] +'\n' ); var object_channel_id = object[object_keys[i]]; ////console.log( object_channel_id ); // this will happen on midnight, we shall reset data if( get_hours() == 0 || get_hours() == '00' ){ // this is midnight lets save save the count at this time localStorage.removeItem( 'check_save' ); if( localStorage.getItem( 'check_save' ) != '1' || localStorage.getItem( 'check_save' ) === null ){ if( channel_id == object_channel_id ) previous_data[channel_id] = sub_count; } } // what if the application started ranning past midnight? For that reason we shall start daily count from that time/* if( localStorage.getItem( object_keys[i] === null ) ){ //console.log( 'storange '+ i +' is null\n' ); localStorage.setItem( object_keys[i], sub_count ); } else { $( target_class ).find( '.count-daily num' ).html( get_daily_count( object, sub_count, i ) ); ////console.log( 'storange at position '+ i +' is not null\n' ); }*/ if( localStorage.getItem( 'previous_data' ) === null ){ //console.log( 'previous data '+ i +' is null ' ); previous_data[channel_id] = sub_count; } else { // calculate the daily count var todays_count = count_daily_count( the_previous_data_object_string, channel_id, sub_count ); $( '#'+channel_id ).find( '.count-daily num' ).html( todays_count ); } } if( get_hours() == 0 || get_hours() == '00' ){ // this is midnight lets save save the count at this time localStorage.removeItem( 'check_save' ); if( localStorage.getItem( 'check_save' ) != '1' || localStorage.getItem( 'check_save' ) === null ){ localStorage.setItem( 'previous_data', JSON.stringify(previous_data) ); localStorage.setItem( 'check_save', '1' ); } } if( localStorage.getItem( 'previous_data' ) === null ){ ////console.log( 'previous data '+ i +' is null ' ); localStorage.setItem( 'previous_data', JSON.stringify(previous_data) ); } localStorage.setItem( 'new_count', JSON.stringify(new_count_object) ); }); } function get_url( object ){ var channel_ids = ""; const all_keys = Object.keys( object ); var totalCount = all_keys.length; index = 1; $.each(object, function(key, value) { if( index != totalCount ){ channel_ids += value +','; } else { channel_ids += value; } index ++; }); return "https://www.googleapis.com/youtube/v3/channels?part=statistics&id=" + channel_ids +"&key=AIzaSyCA6Os6n4FbiV2Jag8hWlUfAfBCtmd24cE"; }function get_live_data( object ){ setTimeout( get_live_data, 5000, object ); get_json_data( object, true ); //console.log( object ); }Esentially my code works perfectly fine and even fetches the API every 5 seconds, but subscriber count never changes. What I did is, I created some random number that keeps increasing, but I'm worried that my users will see it's fake.
this is how I'm getting the random numbers to increase but to be frank I'm feeling guilty because it looks fake.
function get_increase(min, max){ return Math.floor(Math.random()*(max-min+1)+min);}what are these guys doing? From this video? https://www.youtube.com/watch?v=ftMnmPC82qM&ab_channel=MDM, or even social blade. which apis do they use, or how should I approach it?
Is there unique url for live subscriber count😪?