【问题标题】:How to access the trello API from within a powerup?如何从通电中访问 trello API?
【发布时间】:2017-11-08 11:25:32
【问题描述】:

如何在 powerup 中查询 trello API?这似乎是一个显而易见的问题,但我似乎找不到涵盖的内容。

到目前为止,我的简单加电看起来像这样:

var boardButtonCallback = function(t){
  return t.popup({
    title: 'Tools',
    items: [
      {
        text: 'Hide Duplicates',
        callback: function(t){

          var cardQueryCb = function(result){
            console.log(result);
          }
          var cardQ = 'https://trello.com/1/boards/[board_id]/cards/all';
          fetch(cardQ).then(function(response) {
            return response.json();
          }).then(function(data) {
            console.log(data);
          });

          return t.cards('id', 'name')
          .then(cardQueryCb);
        }
      }
    ]
  });
};

TrelloPowerUp.initialize({
  'board-buttons': function(t, options){
    return [{
      text: 'Duplicates',
      callback: boardButtonCallback
    }];
  }
});

调用 fetch 后的响应对象表示该调用未经授权。

我原以为从加电上下文中调用此代码将被视为已授权。当我登录到 trello 时,我可以将该地址放入我的浏览器并获得有效响应 - 为什么 javascript 调用也不会产生有效响应?

更重要的是,我怎样才能从该 URL 获得成功的响应?

【问题讨论】:

    标签: javascript trello trello-powerup


    【解决方案1】:

    由于您的启动是通过 iframe 运行的,它实际上并不是来自 Trello 页面本身,因此您需要在 GET URL 中指定您的 API 密钥和令牌。

    例子:

    https://api.trello.com/1/boards/560bf4298b3dda300c18d09c?fields=name,url&key={YOUR-API-KEY}&token={AN-OAUTH-TOKEN}

    获取 API 密钥和令牌的信息可以在这里找到:https://trello.readme.io/v1.0/reference#api-key-tokens

    【讨论】:

    • 我可以看到,文档链接,如何获取 API-KEY,但是在哪里或如何生成 aouth-token?
    • 此页面可以让您开始了解如何为 trello 获取 oauth 令牌:developers.trello.com/page/authorization
    猜你喜欢
    • 2021-01-30
    • 1970-01-01
    • 2016-03-14
    • 2017-01-09
    • 1970-01-01
    • 2016-02-27
    • 2016-11-03
    • 2021-03-22
    • 1970-01-01
    相关资源
    最近更新 更多