I'm trying to get my trek token by using this javascript function that is executed when a button is pressed, picks up a key, calls the treble api to get a token and then sends the apikey and the token. By including Trello's call to the api I stop working, I do not know what I'm doing wrong, any suggestions? According to the Trello API you should skip a popup window to allow access, I tried the TrelloAuthorize function in the HTML and it does.
$('#btn').click(function() {
var apikey = document.getElementById("login").value;
//Obtengo el Token de Trello
$(window).load(function(){
Trello.authorize({
name: "Task Slayer",
type: "popup",
interactive: true,
expiration: "never",
success: function () { onTrelloAuthorizeSuccessful(); },
scope: { write: true, read: true },
});
// Save the token after success call
function onTrelloAuthorizeSuccessful(var apikey) {
var token = Trello.token();
return token
}
});
$.ajax({
type: 'POST',
data: {
// Nombre de la propiedad que que recibe el valor de x en el backend
api_key: apikey,
token:onTrelloAuthorizeSuccessful()
},
url: 'http://localhost:8080/HelloSpringMVC/hello',
success: function(response) {
console.log(response);
// Hacer algo con la respuesta
},
error: function(e) {
console.log(e);
}
});
});