i'm trying to get my trello token using this javascript function that runs on button press, collects a key, calls trello api to get a token, then sends the apikey and token. When I included the call to the Trello api it stopped working, I don't know what I'm doing wrong, any suggestions? According to the Trello API, a popup window should pop up 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);
}
});
});
In the code you post, I find 2 details:
Trello.authorize()
within a.load()
ofjQuery
, which is incorrect.onTrelloAuthorizeSuccessful()
expects a parameter that is never passed to the routine, and although this does not affect the functionality of the program you should clearly check what you want to do.Try commenting out the
.load()
ofjQuery
, as follows: