PayPal Subscriptions

I am trying to get a PayPal access token using the instructions at this URL: https://developer.paypal.com/docs/api/overview/#get-an-access-token

I have followed the instructions at the URL to the letter and have built the following sample code in JavaScript. When I run it I get a 401 error - user not authorized.

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
</head>
<body>
    <h1>Get Access Token</h1>
    <script>
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function () {
            if (this.readyState == 4 && this.status == 200) {
                console.log(xhttp.responseText);
            }
            else {
               console.log("Status: " + xhttp.status)
            }
        };
        url = "https://api.sandbox.paypal.com/v1/oauth2/token"
        clientID = "AY_6HpYodeIdCyCSWmIuTTX6P4PfcO1tcehekaSk9uwSBhav1SILCD0MZ_E3dRMVXiPdmE-YimahYtQy"
        secret = "EHLlKnunCQtuTdqjnl6QX9ZnuQgMllZKozf-VNHeys9tDssQc0xlXi4_0se1M-VxT8gOHGaSVS3M-2an"
        xhttp.open("post", url, false, clientID, secret);
        xhttp.setRequestHeader("Accept", "application/json");
        xhttp.setRequestHeader("Accept-Language", "en_US");
        xhttp.setRequestHeader("content-type", "application/x-www-form-urlencoded");
        xhttp.send("grant_type=client_credentials");
        console.log(xhttp.status);
    </script>
</body>
</html>

The clientID and secret came from the PayPal My Apps and Credentials link:

PayPal My Apps and Credentials Page

Can anyone help? Thanks