Javascript net::ERR_ABORTED 400 when Getting the Access Token
const client_id = '{client_id}';
const client_secret = '{client_secret}';
const authBase64 = btoa(client_id+':'+client_secret);
const options = {
method: 'POST',
mode: 'no-cors',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
Authorization: 'Basic '+authBase64
}
};
let code = findGetParameter('code');
if (!code) {
location.href = 'https://authz.constantcontact.com/oauth2/default/v1/authorize?client_id='+client_id+'&response_type=code&scope=contact_data&state=12345&redirect_uri='+redirect_uri;
}
console.log('code: '+code);
document.getElementById('authorization_code').innerText = code;
let url = 'https://authz.constantcontact.com/oauth2/default/v1/token?code='+code+'&redirect_uri='+redirect_uri+'&grant_type=authorization_code';
response = fetch(url, options);
if (response.ok) {
console.log('response.status: '+response.status);
document.getElementById('response').innerText = response.json();
}
1 reply