问题描述
我希望在我的电路板上的其中一个 Trello 列表中获取前几张卡片的名称、标签和截止日期,并使用我的机器人通过 discord 发送它。我将如何获取这些信息?
解决方法
您必须使用那里的 API,并使用 fetch 库来发出请求。他们给出了一些如何像这样使用他们的 API 的例子:
// This code sample uses the 'node-fetch' library:
// https://www.npmjs.com/package/node-fetch
const fetch = require('node-fetch');
fetch('https://api.trello.com/1/cards?key=0471642aefef5fa1fa76530ce1ba4c85&token=9eb76d9a9d02b8dd40c2f3e5df18556c831d4d1fadbe2c45f8310e6c93b5c548&idList=5abbe4b7ddc1b351ef961414',{
method: 'POST'
})
.then(response => {
console.log(
`Response: ${response.status} ${response.statusText}`
);
return response.text();
})
.then(text => console.log(text))
.catch(err => console.error(err));
您有很多选项需要处理,就像 php 选项 (link/page?option=WhatsYouWAnt&option2=...
)。
API 页面上列出了所有选项。它使用承诺来返回答案,所以一定要知道你在做什么。
API:Trello API