Am storing some data(eg:temperature) in the google spread sheet. So now i want to fetch the data from my google spread sheet and display it in my react native android application. Can some one give me some ideas or example?
问题:
回答1:
If your data is public:
1 - Publish the file (File menu, publish)
More details here: https://support.google.com/docs/answer/37579?hl=en
2 - Make a GET request 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
Source: https://developers.google.com/gdata/samples/spreadsheet_sample
Notes:
I tested both urls from above and they work OK but it would be good to make sure you are accessing the latest Google API. The endpoints I provided are for API_V3 but a V4 has been released recently.
To migrate and use V4 endpoints check these links: https://developers.google.com/sheets/api/guides/migration https://developers.google.com/sheets/api/samples/reading
To use the V4 you'll need to set and use use an API_KEY
If you make too many requests to google for the data you might have to consider some caching.
3. Extract the data you need from the response and format it according to your needs.
If your data is not public you have to authorize the request: https://developers.google.com/sheets/api/guides/authorizing.
I would probably consider using a node package to handle the private data case https://stackoverflow.com/a/42765674/1979861
回答2:
You can use following node package to get this done: google-spreadsheet
There is also a offical package: NodeJS Google Spreadsheet API