看起来您正在尝试将两种不同的方式结合使用Trello的API - 使用 client.js 并发出直接的HTTP请求。
我建议首先使用 client.js 因为它在使用Trello的API时提供了许多辅助函数。例如, .authorize() 方法将引导您为API密钥生成令牌并将其存储在本地。要仅使用您的示例中的卡片数据请求 client.js 你的代码应该是这样的:
client.js
.authorize()
<html> <script src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> <script src="https://trello.com/1/client.js?key=XXXXXXXXX"></script> <script> var requestSuccess = function(response) { console.log(JSON.stringify(response, null, 2)); } var authenticationSuccess = function() { console.log('Successful authentication'); // Now that you are authenticated, you can start // making requests to the API window.Trello.rest("GET", "cards/5a42e1936434a7d84ba3f5f/members", requestSuccess); }; var authenticationFailure = function() { console.log('Failed authentication'); }; window.Trello.authorize({ type: 'popup', name: 'Work Requests App', scope: { read: 'true', write: 'true' }, expiration: 'never', success: authenticationSuccess, error: authenticationFailure }); </script> </html>
您需要包含您的API(从访问中获取) trello.com/app-key 当你加入时,登录Trello) client.js 在脚本中。更换 XXXXXXXXX 上面有你的API密钥。
XXXXXXXXX
如果你想向Trello的API发出直接的HTTP请求,你需要生成一个令牌(你可以从你检索API密钥的同一页面上这样做),你的代码看起来像这样:
<html> <script> var xhr = new XMLHttpRequest(); xhr.addEventListener("readystatechange", function () { if (this.readyState === this.DONE) { console.log(this.responseText); } }); var yourToken = "XXXXXXXXXX"; var yourKey = "XXXXXXXXXX"; xhr.open("GET", "https://api.trello.com/1/cards/5a42e1936434a7d84ba3f5f/members?key=" + yourKey + "&token=" + yourToken); xhr.send(); </script> </html>
同样,您需要添加API密钥和令牌。