How to get a permanent user token for writes using the Trello API?

后端 未结 3 1575
攒了一身酷
攒了一身酷 2020-12-23 10:02

I\'m trying to write an app that updates my Trello cards with the API. How do I get a permanent user token for the app to write to my Trello board?

Thanks

3条回答
  •  离开以前
    2020-12-23 10:40

    If you have to do everything server-side, Andy Jones is correct, those are the only two ways.

    It should be noted, however, that if you can write javascript+jquery code rather than having to do the redirections server-side, you can take advantage of Trello's client.js wrapper, which does exactly what Andy described, but takes care of most of it for you, which is way convenient.

    And, as I recently discovered, if you do need to do processing server-side, you can still probably use client.js, then just get the token with Trello.token() in your auth success handler, and pass that to your server-side code. It looks like this:

    // include whatever version of jquery you want to use first
    
    
    // call this whenever you want to make sure Trello is authenticated, and get a key. 
    // I don't call it until the user needs to push something to Trello,
    // but you could call it in document.ready if that made more sense in your case.
    function AuthenticateTrello() {
            Trello.authorize({
                name: "your project name",
                type: "popup",
                interactive: true,
                expiration: "never",
                success: function () { onAuthorizeSuccessful(); },
                error: function () { onFailedAuthorization(); },
                scope: { write: true, read: true },
            });
     }
    
    function onAuthorizeSuccessful() {
        var token = Trello.token();
        // whatever you want to do with your token. 
        // if you can do everything client-side, there are other wrapper functions
        // so you never need to use the token directly if you don't want to.
    }
    
    function onFailedAuthorization() {
        // whatever
    }
    

提交回复
热议问题