如何使用 Trello API Batch 方法

问题描述 投票:0回答:2

我正在学习 Trello API,大部分并不困难。然而,用于批处理 GET 请求的批处理方法确实有潜力最大限度地减少流量等。但是,我无法让它工作。它总是抱怨无效的令牌。不过,如果我在 GET URL 中附加令牌,似乎并不重要。

有人有工作批处理示例吗? (在浏览器中有效的简单 URL 字符串?)

谢谢!

trello
2个回答
1
投票

这对我有用......

https://api.trello.com/1/batch?urls=/members/me/boards,/members/me&key=YOUR_KEY&token=YOUR_TOKEN

即同时从 '/members/me/boards' 和 '/members/me' 获取。

Client.js 登录并为您获取数据会更容易一些(它也会为您获取密钥和令牌)。试试这个...

// Call this function
function trelloBatchTest() {

    // Try to log into Trello before getting data
    if (Trello.authorized() === false) {
        Trello.authorize({
            type: "popup",
            interactive: true,            
            scope: { read: true, write: true, account: true },
            success: function () {
                getBatchData();
            },
            error: function () {
                console.log("error logging in");
            }
        });
    }

    // Get data straight away if already logged in
    else {
        getBatchData();
    }         
}

// Makes a batch GET request to Trello - called from function above
function getBatchData() {
    Trello.get("/batch?urls=/members/me/boards,/members/me", function(data) {
        console.log(data);
    }, function (error){
        console.log(error);
    });
}

希望有帮助:)


0
投票

对于那些使用Python的人

使用请求库:

urls = []
for card in cards[0:5]:
    urls.append(f"/cards/{card['id']}/attachments")

query = {
    'urls' : urls,
    'key' : trelloKey,
    'token' : trelloToken
}
response = requests.request("GET", "https://api.trello.com/1/batch", params=query)

对于那些安装了 trello 库的人 (https://pythonhosted.org/trello/trello.html)

board_id = ""
cards = trello.boards.get_card(board_id )

urls = []
for card in cards[0:5]:
    urls.append(f"/cards/{card['id']}/attachments")

response = trello.batches.get(urls)

批量 API 文档没有显示 url 的格式。请注意在构建 url 列表时删除了 https://api.trello.com/1 部分。

© www.soinside.com 2019 - 2024. All rights reserved.