2016-11-12 133 views
0

我必須使用trello API進行工作,但我得到錯誤400(無效令牌),我不知道爲什麼。
這是我的代碼(我已經取代我的實際鍵與mykeyTrello api無效令牌

<html> 
    <head> 
    <title>A Trello Dashboard</title> 
    <link rel="stylesheet" media="screen" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
    </head> 
    <body> 
    <div class="container"> 
     <h1>Trello Dashboard</h1> 
    </div> 
    </body>  

    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 
    <script src="https://trello.com/1/client.js?key=mykey"></script> 

    <script type="text/javascript"> 
    Trello.authorize({ 
     type: 'popup', 
     name: 'A Trello Dashboard', 
     scope: { 
     read: 'true', 
     write: 'true' 
     }, 
     expiration: 'never', 
     success: function() { console.log("Successful authentication"); }, 
     error: function() { console.log("Failed authentication"); } 
    }); 
    </script> 
</html> 

回答

0

你應該把你所有的代碼邏輯中的document.ready,所以整個文檔將做好準備,那麼只有你會得到彈出用於認證/授權。你可以在這裏得到有效的應用程序鍵:https://trello.com/app-key查看代碼示例:

<html> 
    <head> 
    <title>A Trello Dashboard</title> 
    <link rel="stylesheet" media="screen" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> 
    </head> 
    <body> 
    <div class="container"> 
     <h1>Trello Dashboard</h1> 
    </div> 
    <div id="loggedin"> 
    <div id="header"> 
     Logged in to as <span id="fullName"></span> 
    </div> 

    <div id="output"></div> 
</div>  

    </body>  

    <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script> 
    <script src="https://api.trello.com/1/client.js?key=[appKeygoeshere]"></script> 

    <script type="text/javascript"> 
    $(window).load(function(){ 
    Trello.authorize({ 
     type: 'popup', 
     name: 'A Trello Dashboard', 
     scope: { 
     read: 'true', 
     write: 'true' 
     }, 
     expiration: 'never', 
     success: function() { console.log("Successful authentication"); 
      Trello.members.get("me", function(member){ 
      $("#fullName").text(member.fullName); 

      var $cards = $("<div>") 
       .text("Loading Cards...") 
       .appendTo("#output"); 

      // Output a list of all of the cards that the member 
      // is assigned to 
      Trello.get("members/senthil192/cards/all", function(cards) { 
       $cards.empty(); 
       $.each(cards, function(ix, card) { 
        //alert(card.name); 
        $("<a>") 
        .attr({href: card.url, target: "trello"}) 
        .addClass("card") 
        .text(card.name) 
        .appendTo($cards); 
       }); 
      }); 
     }); 
     }, 
     error: function() { console.log("Failed authentication"); } 
    }); 
    }); 

    </script> 

</html> 

碼參考網址:http://jsfiddle.net/danlec/nNesx/