Write to a Google spreadsheet from JavaScript using the Public API access (no OAuth)

我只是一个虾纸丫 提交于 2020-01-04 17:21:05

问题


I'd like to allow a user to visit one of my sites, enter some information into a field, and then save that information into a Google Spreadsheet via JavaScript.

  • I don't want the user to login via Google or have to do any special authentication.
  • It's Ok if the spreadsheet needs to be open to public; the data's not sensitive.
  • I don't want to use a Google Form, I want to have full control over the client-side UI.

I've been reading through the Google developer docs, but they only make mention to an OAuth login solution. The Google Developer Console allows you to create a "Public API access key", but does not explain how it's used.


回答1:


All of the examples are for the scenario where the user is using your app to access his own files. In your case, you want the app to access your own file. This isn't easy. The only ways I can see are :-

  1. Use a server app (appengine works well) to do the access
  2. Very carefully set up permissions and store a refresh token in your app.

Option 2 could be your worst security nightmare if you don't do it carefully, and even then may be an infringement of Google T's and C's since it's akin to distributing your password.

Once you figure out the auth, you'll need to check out the spreadsheet API (https://developers.google.com/google-apps/spreadsheets/), as this is the API that allows you to update an existing spreadsheet. The Drive API can only upload an entire new spreadsheet.



来源:https://stackoverflow.com/questions/29332794/write-to-a-google-spreadsheet-from-javascript-using-the-public-api-access-no-oa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!