Salve a tutti, sto cercando invano da ore a tentare un autenticazione con twitter del tipo solo per applicazioni. Ho preso questo codice dalla rete ma a me il server torna sempre l'errore 403 forbidden eppure la richiesta sembra impostata bene. Vi scrivo sotto il codice anche con le key personali se volete provarlo,poi le modificherò in futuro.


codice:
function getTwitterConsumerTokens() {
    return {key: "uhZQz8o0r2GZxy6bA42dsOuXC", secret: "bgxg3UPsfRtGKyCae0LCwtpZeVLSh12z4801Y8FUqs1zt4Bx43"};
}






var s = encodeURIComponent(getTwitterConsumerTokens().key,'RFC 1738');
s += ':'+encodeURIComponent(getTwitterConsumerTokens().secret,'RFC 1738');
console.log(btoa(s));


$( document ).ready(function(){
$.ajax({
        type:"POST",
        beforeSend: function (request)
        {
            
            request.setRequestHeader("Authorization", "Basic "+btoa(s));
            request.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");
        },
        url: "https://api.twitter.com/oauth2/token",
        data: "grant_type=client_credentials",
        processData: false,
        success: function(msg) {
            alert("successfull");
        }
});


});