0

我正在使用 coinbase 开发 API 来访问资产。
要访问费率数据,需要 API 从 POST 请求发回的访问密钥。
我正在使用Flutures和一个名为Fetch-Futures的模块,而不仅仅是使用基于 promise 的 fetch API。

我以前没用过期货。响应状态正常(200),但我返回的对象中的所有选项都说在它们旁边已解决(见屏幕截图)。

解析数据对象中每个键的类型究竟意味着什么?

这是否意味着我应该已经能够使用这些值,或者我是否需要额外的步骤才能返回我的访问令牌?

我想要一个很好的访问方式r.json[_value].access_token

JS:

function exchangeCodeForAccessToken(tempCode) {
  const accessTokenURL = exchangeCode.url(tempCode);

  const getAccessToken = url => {
    console.log(fetchy);
    return fetchy(url, exchangeCode.options)
      .map(r => {
        console.log(2, r.json);
        return r;
      })
      .value(console.log);
  };
4

1 回答 1

0

据我所知,Fetch-Futures 将所有值包装在 Futures 的返回对象中:

https://github.com/theodesp/fetch-future/blob/10af776d2653eaf75aea580b9dd2a52ae9175abd/src/index.js#L42-L59

我不确定这是什么原因*,但这意味着您可能必须将所需的属性展平到外部 Future 中,如下所示:

return fetchy(url, exchangeCode.options)

// I'm using chain instead of map, because chain flattens the Future
// And since r.json is a Future, that works out:
.chain(r => r.json)

//Now I can map, and the value will be what was inside r.json:
.map(json => json.accessToken)

* 如果我是你,我可能会使用 Fetch-Futures 以外的东西。它似乎有些过时,可能无法与最新版本的 Fluture 一起使用,并且使用有问题的 API 设计来包装输出值。

于 2020-01-07T16:17:24.397 回答