Sto tentando di autorizzare una sessione di Last.fm e sto facendo fatica a firmare correttamente una richiesta per una chiave di sessione.Autenticazione con Last.fm in Jquery - Firma del metodo non valida fornita
Continuo a ricevere Invalid method signature supplied
Tuttavia, quando eseguo l'hash MD5, credo che la query debba consistere al di fuori di JS, ottengo la stessa firma. Devo includere i dati errati nella stringa, credo, ma non riesco a capire cosa.
So che ci sono alcune altre domande e le ho esaminate tutte per vedere cosa sta andando storto qui, ma giuro che sembra giusto per me.
Questo è l'algoritmo di firma e la chiamata Ajax. Ho provato a lasciare abbastanza dati di esempio.
// Set elsewhere but hacked into this example:
var last_fm_data = {
'last_token':'TOKEN876234876',
'user': 'bob',
'secret': 'SECRET348264386'
};
// Kick it off.
last_fm_call('auth.getSession', {'token': last_fm_data['last_token']});
// Low level API call, purely builds a POSTable object and calls it.
function last_fm_call(method, data){
// param data - dictionary.
last_fm_data[method] = false;
// Somewhere to put the result after callback.
// Append some static variables
data['api_key'] = "APIKEY1323454";
data['format'] = 'json';
data['method'] = method;
post_data = last_fm_sign(data);
$.ajax({
type: "post",
url: last_url,
data: post_data,
success: function(res){
last_fm_data[method] = res;
console.log(res['key'])// Should return session key.
},
dataType: 'json'
});
}
function last_fm_sign(params){
ss = "";
st = [];
so = {};
Object.keys(params).forEach(function(key){
st.push(key); // Get list of object keys
});
st.sort(); // Alphabetise it
st.forEach(function(std){
ss = ss + std + params[std]; // build string
so[std] = params[std]; // return object in exact same order JIC
});
// console.log(ss + last_fm_data['secret']);
// api_keyAPIKEY1323454formatjsonmethodauth.getSessiontokenTOKEN876234876SECRET348264386
hashed_sec = unescape(encodeURIComponent($.md5(ss + last_fm_data['secret'])));
so['signature'] = hashed_sec; // Correct when calculated elsewhere.
return so; // Returns signed POSTable object
}
Qualcuno può vedere che mi manca qui? Sono assolutamente perplesso sul motivo per cui questo non sta restituendo un oggetto POSTable correttamente firmato nel formato richiesto here. Grazie per il tuo tempo.
Modifica: non posso ringraziare nessuno per il loro tempo se non ho alcun consiglio! Nessuno ha avuto esperienza con last.fm?
Provare a rimuovere 'data [ 'format'] = 'json';' – George
Grazie, cercherò questo insieme al rispondi sotto – TechnicalChaos
Cheers, anche se leggermente fuori - Ho modificato la mia risposta qui sotto con quello che ho trovato riguardo all'attributo format. – TechnicalChaos