34

我正在尝试编写一个使用 API 更新我的 Trello 卡的应用程序。如何获取应用程序的永久用户令牌以写入我的 Trello 看板?

谢谢

4

3 回答 3

59

您可以通过以下两种方式之一执行此操作 -

将用户引导至以下地址。这会将用户引导至具有令牌的页面,她可以将其复制并粘贴回给您。重要的是你要求expiration = neverscope = read,write

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

或者使用 OAuth(更难)自动请求访问令牌。在文档中阅读更多内容。

获得令牌后,您可以进行任何您想要的 API 调用。

于 2013-06-25T15:14:20.563 回答
11

如果你必须在服务器端做所有事情,Andy Jones 是正确的,那是仅有的两种方式。

但是,应该注意的是,如果您可以编写 javascript+jquery 代码,而不必在服务器端进行重定向,则可以利用 Trello 的 client.js 包装器,它完全符合 Andy 的描述,但可以处理大部分给你,这很方便。

而且,正如我最近发现的那样,如果您确实需要在服务器端进行处理,您仍然可以使用 client.js,然后只需在您的身份验证成功处理程序中使用 Trello.token() 获取令牌,并将其传递给您的服务器侧代码。它看起来像这样:

// 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
}
于 2013-09-03T21:02:42.943 回答
0

如果您只需要个人使用的令牌,您可以获得app-keysecret并且token基于您在此处登录。

于 2017-03-14T10:24:04.463 回答