简体   繁体   中英

Using client.js library for Trello API

I'm new with trello API. As suggested by Trello, I'm trying to use the client.js library. I followed the instructions, and i get a 'Successful authentication' message in the console, but yet I get a 401 error(in the console):

POST https://api.trello.com/1/cards 401 ()            jquery-1.7.1.min.js:4 

Here is my code:

 <head>
    <title>Trello api</title>

 <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
 <script src="https://api.trello.com/1/client.js?    
  key=[my key]"></script>
</head>
<body>
   <script>
      var authenticationSuccess = function() { console.log('Successful  
      authentication'); };
      var authenticationFailure = function() { console.log('Failed    
      authentication'); };

Trello.authorize({
      type: 'popup',
      name: 'Getting Started Application',
      scope: {
      read: true,
      write: true },
      expiration: 'never',
      success: authenticationSuccess,
      error: authenticationFailure
      });


var myList = 'my list';
var creationSuccess = function(data) {
       console.log('Card created successfully. Data returned:' +   
       JSON.stringify(data));
};
var newCard = {
       name: 'New Test Card', 
       desc: 'This is the description of our new card.',
       idList: myList,
       pos: 'top'
       };
  Trello.post("cards", newCard, creationSuccess);


  </script>

Any ideas? Thanks.

The problem is you are supplying a idList that doesn't exist, 'my list'

You need to follow the instructions here: https://developers.trello.com/get-started/start-building to get the correct idList value.

'

I had the same issue. I take 'login' and 'logout' from http://jsfiddle.net/A3Xgk/2/ , and it is working.

Trello.authorize({
    interactive: false,
    success: onAuthorize
});

$("#connectLink").click(function() {
    Trello.authorize({
        type: "popup",
        success: onAuthorize
    });
});

If it will not help, please write me, I give to you my code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM