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

后端 未结 3 1554
攒了一身酷
攒了一身酷 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:20

    You can do this in one of 2 ways -

    Direct the user to the below address. This will direct the user to a page that has a token that she can copy and paste back to you. The important bit is that you ask for expiration = never and scope = read,write

    https://trello.com/1/authorize?key=substitutewithyourapplicationkey&scope=read%2Cwrite&name=My+Application&expiration=never&response_type=token
    

    Or use OAuth (harder) to automate the request for an access token. Read more in the documentation.

    Once you have the token, you can make any API call you'd like.

    0 讨论(0)
  • 2020-12-23 10:39

    If you only need a token for personal use you can get app-key, secret and token based on you being logged in over here.

    0 讨论(0)
  • 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
    <script src="https://api.trello.com/1/client.js?key=[your application key]" type="text/javascript"></script>
    
    // 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
    }
    
    0 讨论(0)
提交回复
热议问题