我在谷歌电子表格中存储一些数据(例如:温度)。所以现在我想从我的谷歌电子表格中获取数据并将其显示在我的 React Native Android 应用程序中。有人可以给我一些想法或例子吗?
如果您的数据是公开的:
1 - 发布文件(文件菜单,发布)
更多详细信息请参见此处:https://support.google.com/docs/answer/37579?hl=en https://support.google.com/docs/answer/37579?hl=en
2 - 发出 GET 请求 to
https://spreadsheets.google.com/feeds/list/<SPREAD_SHEET_ID>/od6/public/values?alt=json
or to
https://spreadsheets.google.com/feeds/cells/<SPREAD_SHEET_ID>/<SHEET_NUMBER>/public/basic?hl=en_US&alt=json
来源:https://developers.google.com/gdata/samples/spreadsheet_sample https://developers.google.com/gdata/samples/spreadsheet_sample
Notes:
-
我测试了上面的两个网址,它们工作正常,但最好确保您正在访问最新的 Google API。我提供的端点适用于 API_V3,但最近发布了 V4。
要迁移和使用 V4 端点,请检查以下链接:https://developers.google.com/sheets/api/guides/migration https://developers.google.com/sheets/api/guides/migration
https://developers.google.com/sheets/api/samples/reading https://developers.google.com/sheets/api/samples/reading
要使用 V4,您需要设置并使用 API_KEY
如果您向谷歌发出太多数据请求,您可能需要考虑一些缓存。
3. 从响应中提取您需要的数据并根据您的需要对其进行格式化。
如果您的数据不公开,您必须批准该请求:https://developers.google.com/sheets/api/guides/authorizing https://developers.google.com/sheets/api/guides/authorizing.
我可能会考虑使用节点包来处理私有数据情况https://stackoverflow.com/a/42765674/1979861 https://stackoverflow.com/a/42765674/1979861
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)