And*_*nes 56
您可以通过以下两种方式之一完成此操作 -
将用户定向到以下地址.这会将用户定向到一个页面,该页面具有可以复制并粘贴给您的令牌.重要的是你要求expiration = never和scope = read,write
https://trello.com/1/authorize?key=substitutewithyourapplicationkey&scope=read%2Cwrite&name=My+Application&expiration=never&response_type=token
Run Code Online (Sandbox Code Playgroud)
或者使用OAuth(更难)自动化访问令牌请求.阅读文档中的更多内容.
获得令牌后,您可以进行任何您想要的API调用.
nem*_*nem 11
如果你必须做服务器端的所有事情,Andy Jones是正确的,那么这是唯一的两种方式.
然而,应该注意的是,如果你可以编写javascript + jquery代码而不是必须在服务器端进行重定向,那么你可以利用Trello的client.js包装器,它完全符合Andy的描述,但是可以处理大多数问题.这对你来说很方便.
而且,正如我最近发现的,如果你确实需要处理服务器端,你仍然可以使用client.js,然后在你的auth成功处理程序中获取带有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
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
12213 次 |
| 最近记录: |