通过本地反应应用程序从 Google 表格中获取数据的响应不一致 [英] Inconsistent response fetching data from Google Sheet via local react app

查看:10
本文介绍了通过本地反应应用程序从 Google 表格中获取数据的响应不一致的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经制作了一个 create-react-app,我在我的机器上静态构建和运行它作为 OBS 插件,没有使用 Hashrouter 的服务器.我正在从已设置为公开的 Google 表格中获取数据.使用这种格式的网址 https://spreadsheets.google.com/feeds/list/{SpreadsheetID}/{sheetNo}/public/values?alt=json 我能够获取数据为在我的应用程序中使用的 JSON.但是,过去一周的响应变得不一致,应用没有任何变化.

I've made a create-react-app that I build and run statically on my machine as an OBS plugin with no server using Hashrouter. I'm fetching data from a Google Sheet that I have set to public. Using a url in this format https://spreadsheets.google.com/feeds/list/{SpreadsheetID}/{sheetNo}/public/values?alt=json I'm able to fetch data as JSON to use in my app. However, the responses have become inconsistent in the past week with no changes to the app.

当我在浏览器中访问 URL 时,它总是加载 JSON 的纯文本版本.但是,在我的应用程序中发送 GET 请求时,有 60% 的时间会出现 404 错误.我在请求中尝试了不同的标头,但似乎找不到任何可以始终如一地工作的东西.

When I go to the URL in a browser, it never fails to load a plain text version of the JSON. However, when sending a GET request in my app, I get at 404 error 60% of the time. I've tried different headers in my request, but I can't seem to find anything that works consistently.

这是我进行提取的函数.我在 useEffect 挂钩中调用它.

Here's the function where I do the fetch. I'm calling this from within a useEffect hook.

const getData = async (url) => {
  try {
    const response = await fetch(url);
    if (!response.ok) {
      throw new Error(`fetch error. status: ${response.status}`);
    }
    return await response.json();
  } catch (err) {
    return err;
  }
};

我收到的 404 响应说:抱歉,目前无法打开文件.请检查地址,然后重试."

The 404 response I get says: "Sorry, unable to open the file at this time. Please check the address and try again."

我认为这与我在没有运行服务器的情况下从本地文件调用这一事实有关.如果可能的话,我想保持这种方式,只是为了让 OBS 运营商变得简单.我尝试将 API 密钥添加到我的 fetch url (key={APIKEY}) 中,但这似乎没有任何区别.关于可能导致此行为的任何想法?

I figure it has something to do with the fact that I'm calling from a local file without a server running. I'd like to keep it this way if possible just to make things simple for OBS operators. I've tried adding an API key to my fetch url (key={APIKEY}) but that didn't seem to make any difference. Any thoughts on what might be causing this behavior?

推荐答案

这是一个已知问题.请看这个线程.https://support.google.com/docs/thread/121088347

This is a known problem. Please see this thread. https://support.google.com/docs/thread/121088347

这篇关于通过本地反应应用程序从 Google 表格中获取数据的响应不一致的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆