问题
I am importing private data into Google Spreadsheet using the function ImportXML. To make this work, I have written an API. However, since the data in private I would like to make the API private. I can do that. The problem is to do it in a way so that Google Spreadsheet can communicate with my custom API.
Preferably, I would like to use OAuth 2.0 with the user logged into Google Spreadsheet. Is this possibly?
Other suggestions are welcome.
回答1:
This is possibly. First, make your custom API use Google auth.
In a Google Apps Script in your Google Spreadsheet
- Fetch the URI to initialize auth with your API
- Follow the redirect
Doing these two steps you recieve some kind of token to prove you are logged in. Use this then contacting the API for data.
Be advised, if you use an installed app, the user authenticating will be the one who installed the app, not the one opening the spreadsheet. If you do not use an installed app, you can not do this automatically then you open the spreadsheet because non-installed apps cannot authenticate in the onOpen() method. So you would have to use a menu item, a buttom or whatever to execute the function manually.
来源:https://stackoverflow.com/questions/24140411/import-private-data-into-google-spreadsheet