我正在尝试编写一个使用API更新我的Trello卡片的应用程序。如何获取永久用户令牌以便该应用程序能够写入我的Trello面板?
谢谢。
我正在尝试编写一个使用API更新我的Trello卡片的应用程序。如何获取永久用户令牌以便该应用程序能够写入我的Trello面板?
谢谢。
您有两种方式可以完成此操作 -
将用户直接引导至以下地址。这将引导用户到一个页面,该页面包含一个令牌,用户可以复制并粘贴给您。重要的是您需要请求 expiration = never
和 scope = read,write
https://trello.com/1/authorize?key=substitutewithyourapplicationkey&scope=read%2Cwrite&name=My+Application&expiration=never&response_type=token
或者使用 OAuth(更难)来自动请求访问令牌。在文档中阅读更多信息。
一旦你拥有了令牌,你可以进行任何 API 调用。
// 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
}