Javascript button to get a Trello token

1

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);
        }
      });

    });
    
asked by Silvia 11.03.2018 в 13:58
source

1 answer

1

In the code that you publish, I find 2 details:

  • You are including the Trello.authorize() routine within .load() of jQuery , which is incorrect.
  • The onTrelloAuthorizeSuccessful() function wait for a parameter that is never passed to the routine, and although this does not affect the functionality of the program you should review clearly what you want to do.
  • try commenting the .load() of jQuery , as follows:

      $('#btn').click(function() {
    
            var apikey = document.getElementById("login").value;
    
            //Obtengo el Token de Trello
    //        $(window).load(function(){     <-- comenta esta linea
            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) {   // apikey nunca es pasado a la rutina
            var token = Trello.token();
    
                return token
            }
    //        });                            <-- Comenta esta otra linea
            $.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);
            }
          });
    
        });
        
    answered by 11.03.2018 / 18:49
    source