ReactJS RSS 提要到 Json 转换器

ReactJS RSS Feed to Json converter

我正在使用以下代码将 RSS 提要转换为 JSON 文件:

import React from "react";
import Button from '@material-ui/core/Button';
import Feed from 'rss-to-json'

const App = () => {    

const getFeed = () => {
  Feed.load('https://www.reddit.com/.rss', function(err, rss){
    console.log(rss);
    });
}


  return(
    <Button
      onClick = {() => getFeed()}
       variant="outlined">
      Submit
    </Button>
  ) 

}

export default App;

但我在 cosole 中收到以下错误:

Access to fetch at 'https://www.reddit.com/.rss' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

我不知道如何处理这个错误。

我认为当您访问上面的 rss url 时,您可能需要设置 OAUTH 进行身份验证。其他端点工作正常。看这里 - https://codesandbox.io/s/cocky-worker-u8zo9

您可以获得有关 Reddit API 的 here

的 OAUTH 设置的更多详细信息