My Twitch account status checker stopped working properly and I need help figuring out what went wrong.
I built this tool several months back that lets users input their username to check if their Twitch account has been suspended or not. It was working fine before but now it’s broken and I can’t figure out why.
Here’s the code I’m using:
var validateAccount = function (username) {
$(".info-text").fadeOut(30)
$.getJSON('https://api.twitch.tv/kraken/users/' + encodeURIComponent(username) + '?callback=?').done(function (response) {
if (/.+is unavailable$/.test(response.message)) {
var msg = 'Your account appears to be suspended from Twitch. Please contact '
msg += '<a target="_blank" href="https://help.twitch.tv/customer/portal/emails/new?interaction[name]=' + username + '">Twitch support</a> '
msg += 'to understand the reason for suspension.<br />'
msg += '<span>This tool cannot assist with appeals</span>'
displayResult('error', msg)
} else if (/.+is not available on Twitch$/.test(response.message) || /.+does not exist$/.test(response.message)) {
var msg = 'This username either doesn\'t exist or isn\'t a valid Twitch account.'
displayResult('warning', msg)
} else {
var msg = 'This account appears to be active and not suspended. '
msg += 'If you\'re still having access issues, try disabling VPN or proxy services.<br/><br/>'
msg += 'Remember that Twitch may apply IP-based restrictions, so check other accounts too.<br/><br/>'
msg += 'If problems persist, your IP might be flagged. '
msg += '<a style="color: #fff" href="https://help.twitch.tv/customer/portal/emails/new" target="_blank"><strong>Contact support</strong></a> for assistance.'
displayResult('ok', msg)
}
}).fail(function () {
displayResult('warning', 'API request failed. Twitch services might be down.')
})
}
var displayResult = function (status, text) {
var heading = status === 'ok' ? "Account looks good!" :
status === 'warning' ? "Something seems off!" : "Problem detected!"
$('.output').attr('class', 'output')
$('.output').html('<h3>' + heading + '</h3>' + text)
$('.output').addClass(status)
$(".output").fadeIn()
}
$(document).ready(function () {
$('#username-form').submit(function (event) {
event.preventDefault()
})
$('#username-form').keyup(function (event) {
if (event.keyCode !== 13) return
event.preventDefault()
var inputUser = $('#username-form input').val()
window.location.hash = '#' + inputUser
validateAccount(inputUser)
})
if (location.hash) {
var hashUser = location.hash.substr(1)
$('#username-form input').val(hashUser)
validateAccount(hashUser)
}
})
Any ideas what might be causing the malfunction? The API calls seem to be the same but maybe something changed on Twitch’s end?