How to excecute script every 6 hours? JQUERY : I need to refresh token every 6hours so then I can use an api without doing login again.

I'm trying like this:

    setInterval(function(){
          var code = window.location.href.split("=").pop();      
          var xhr = new XMLHttpRequest();
          xhr.open("POST", "https://api.mercadolibre.com/oauth/token?grant_type=authorization_code&client_id="+appID+"&client_secret="+secretKey+"&code="+code+"&redirect_uri="+redirectUri, true);
          xhr.onload = function () {    
            console.log(xhr.responseText);
          };
          xhr.send();
        }    
    }, 21600);

Any Idea how could achieve this?

