Trello api无效令牌

时间:2016-11-12 10:25:33

标签: javascript trello

我必须使用trello API进行工作,但我收到错误400(无效令牌),我不明白为什么。
这是我的代码(我用gen_random_uuid()替换了我的实际密钥)

mykey

1 个答案:

答案 0 :(得分: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>

code ref url:http://jsfiddle.net/danlec/nNesx/