【问题标题】:Feedly API is returning session expired instead of letting me access the API from local node environmentFeedly API 正在返回会话过期,而不是让我从本地节点环境访问 API
【发布时间】:2020-02-23 22:29:30
【问题描述】:

使用 feedlys api 和 feedly 建议的节点包装器来访问其 api。我没有成功登录。我搜索了文档和任何可用资源,但找不到任何答案,因此我正在联系堆栈溢出社区,看看是否有人使用过这个平台。

我尝试清除缓存。我尝试使用 fetch api 而不是使用我正在尝试实现的节点包装器。

我安装了节点包'feedly'。

将此代码添加到我的服务器:

const Feedly = require('feedly')

const f = new Feedly({
  client_id: 'client_id here',
  client_secret: 'client_secret here',
  base: 'https://cloud.feedly.com/v3/collections/',
  port: 8080
})

async function feedlyStream() {
  const results = await f.reads()
  return console.log('results', results)
}

feedlyStream();

我确实需要登录一个页面,大概这是身份验证,所以我可以检索数据。

我不是后端用户,主要是前端用户,所以以这种方式执行任务对我来说是新的。

当我从控制台运行 nodemon ./server.js 时,它会将我带到一个登录页面,例如 feedlys 网站,但随后我收到错误“会话已过期”。没有其他错误,不在控制台等。

我可以在使用 insomnia 测试 api 端点时获取检索信息,使用与上述相同的确切信息以及不记名令牌。

这是我尝试过的 fetch 版本,与 insomnia 输入的非常相似。


const URL = 'https://cloud.feedly.com/v3/collections/'
const proxyurl = "https://cors-anywhere.herokuapp.com/";

window.onload = () => {
  fetch(proxyurl + URL, {
    credentials: 'same-origin',
    Accept: 'application/json',
    headers:
    {
      'Authorization': 'Bearer TOKEN GOES HERE',
      'Access-Control-Allow-Origin': 'include',
      'Content-Type': 'application/json',
      "client_id": "client_id here", 
      "method": "GET",
      "client_secret": "client_secret here",
    }
  })
    .then(function (data) {
      console.log('data from api', data.body);
      const here = document.getElementById("here")
      const bodyText = () => {
        if (data.body == null) {
          return "Nope, it's null"
        }
        return data.body;
      }
      here.innerHTML = bodyText();
    })
}

这是我从上面的控制台日志收到的内容

data from api ReadableStreamlocked: false__proto__: ReadableStream

任何帮助将不胜感激。谢谢。

【问题讨论】:

    标签: javascript node.js api fetch


    【解决方案1】:

    很简单,我错过了获取的一部分。我需要将响应转换为 JSON。仍然不能用于 fetch 或 apis,这是一个明显但令人讨厌的问题。

          "method": "GET",
          "client_secret": "client_secret here",
        }
      })
    .then(res => res.json();) // this is what i needed to add in :)
     .then(function (data) {
          console.log('data from api', data.body);
    

    【讨论】:

      猜你喜欢
      • 2013-06-12
      • 2014-03-12
      • 1970-01-01
      • 2016-08-03
      • 2014-08-25
      • 2021-03-23
      • 1970-01-01
      • 2017-11-08
      • 1970-01-01
      相关资源
      最近更新 更多