Outdated script no longer works

We need a update for this script. Can someone help? :slight_smile:

function twitchStream() {
twitch_widget.attr(“href”,“https://twitch.tv/” + user_name);
$.getJSON(‘https://api.twitch.tv/kraken/streams/’ + user_name + ‘?client_id=’ + api_key + ‘&callback=?’, function(data) {
if (data.stream) {
if (recntStatChange == 0) {
$( “#livestream, #livestream-button, #livestream iframe” ).removeClass( “hidetwitch” );
visitOffline = 1;
setTimeout(recntAndRefresh, long);
//Displayed the iframe and the user is streaming, refresh period set to long
}
if (recntStatChange == 1) {
setTimeout(refresh, short);
//Refresh period set to short, streaming
}
}
else {
if (recntStatChange == 1) {
$( “#livestream, #livestream-button, #livestream iframe” ).addClass( “hidetwitch” );
$iframe = $( “#livestream, #livestream-button” ).find( “iframe” );
$iframe.attr( “src”, $iframe.attr( “src” ));
setTimeout(recntAndRefresh, long);
//Hid the stream, did a reset on iframe so that the visitor won’t hear any audio if you’d go online again and the twitch-player hasn’t shown yet, refresh period set to long
}
if (recntStatChange == 0) {
if (visitOffline == 0) {
visitOffline = 1;
setTimeout(refresh, long/2);
//The user isn’t streaming and just entered, refresh timeout is set to long divided by 2.
}
else {
//The user isn’t streaming, and the visitor has been here for the widget to update at least once, refresh period set to short
setTimeout(refresh, short);
}
}
}
});
};

The migration guide in the docs gives you all the information you need to switch from using v3 to the v5 endpoints: https://dev.twitch.tv/docs/v5/guides/migration

Keep in mind though that v5 is deprecated and will be removed at some point too, so ideally should rewrite your code to work with the Helix streams endpoint: https://dev.twitch.tv/docs/api/reference/#get-streams

I dont know how that works. Can you help me?

You’ll need to provide the user_login parameter in your JSON URL, in addition to migrating to the New API. In my case, I had to provide the user_id, but try that. All the info on optional parameters are in the API Reference page, like @Dist mentioned.

But to give you a bit of an edge, you’ll need to check if said stream is live. If it is, you’ll need to check its data and if it exists. If it DOES, then you can change the classes from your divs and execute the rest of your function.

There you go https://pastebin.com/95mwfMiA