Collecting data from Google Apps users' spreadsheets programmatically - google-apps-script

We have a number of Google Apps users, each of them has a non-public spreadsheet named 'XData' in their GDrive account. The Google Apps admin needs to be able to do the following:
Click one button that would collect specified data from users' spreadsheets and put it into a master spreadsheet on admin's account.
Click another button that would display the data from master spreadsheet to admin in a nice visual way.
What's the best way to implement such setup using Google tools (Fusion Tables and/or Admin SDK and/or Apps Script and/or Drive SDK and/or Spreadsheets API and/or etc)? The first step is optional if the second one can be accomplished without it.

1 and #2 can be done easily with apps script only if all the spreadsheets are shared with the script owner.
If they are not shared you can only do it with drive api and user delegation of permissions (see the drive api docs)

Related

Unable to open Google xlsx spreadsheet / Also Google Drive permission Blocked

I have a Google Apps Script that I am currently using to successfully open a Google Sheets spreadsheet (read-only shared with my account) and perform some reading functions.
I received another spreadsheet that I would like to run similar processes on.
If I try:
SpreadsheetApp.openById("_______") (which works on the other sheet), I get Exception: Service Spreadsheets failed while accessing document with id _____" with this sheet. This spreadsheet is actually an xlsx on Google Drive (but appears it can still open in Google sheets) rather than a native Google sheet so I figured maybe that was the issue...?
So now I'm trying to instead access it as a Google Drive file using DriveApp.getFileById("____"). However now I get an authorization request to allow my script to access Google Drive. When I authorize it, I get:
This app is blocked
This app tried to access sensitive info in your Google Account. To keep your account safe, Google blocked this access.
I haven't found a way to fix this. I'm on a private Google account, not using a company's Apps.
Any ideas?
Found a solution to the permission issue.
To work with Apps Script, I've modified this from #alper's solution which sources #tellowkrinkle's comment.
Do the following:
Go to https://console.developers.google.com and create a new project for yourself
Search for the Google Drive API in the search box at the top, and turn it on
Click OAuth consent screen on the left and set it up.
Assuming your account isn't part of an organization, you'll have to say your app is for external users and in testing
In the required scopes section, add .../auth/docs and .../auth/drive (I'm not sure which needed, it's probably only one of those). This will probably not be available if you didn't complete (2)
Add the accounts you want to use with your copy of gdrive as testers of your app. Only these accounts will be able to use your copy of gdrive, so everyone will have to compile their own (unless someone goes and gets theirs reviewed by Google). I only added my own account because I am the only one using my App Script which uses my Drive.
Click the 3 dots on the top right and select "Project settings". Make note of the "Project number".
Go to your Apps Script. Go to Resources > Cloud Platform project. Insert the project number from (4).
Next time you try to run your Apps Script, you'll be asked to Authorize but this time you'll have the chance to actually do it successfully.

Determine Script Authorization Requirements

I have a script associated with a spreadsheet which requests Authorization. When granted and I look at the Permissions associated with my account the script has the following:
Has some account access, including Google Docs
Google Docs
View and manage your documents in Google Drive
View and manage your spreadsheets in Google Drive
Additional access
View and manage your forms in Google Drive
I am surprised it is going to this level as all the function calls I am seeing are either getting an active item or getting the sheet by name (not the file, a tab inside the file). Outside of an HTML service form, there is nothing I see which should call a Google Form item. Nor do I see anything about a Doc. Just Spreadsheet items.
Is there any way to determine where the various authorized access items are IN the code without trial and error?

Add-on not available on shareable link sheet

We have a Google Apps domain. The domain has a sheet with a Google Apps Script add-on. We have to share this sheet with people outside our organisation. The add-on is used to refresh the data displayed in the spreadsheet.
When someone who isn't logged in opens the shared link, the add-on is not available for them. Is there a way to get around this?
You will not be able to get around the restriction that requires the user to be logged in.
Your add-on modifies spreadsheet contents on behalf of the user.
That operation requires authorization from the user.
Only logged-in users can grant authorization.
Reference: Develop Add-ons for Google Sheets, Docs, and Forms - Authorization
A separate web service that ran as you, say, and was accessible to "Everyone, including anonymous", could modify a spreadsheet without requiring a user to be logged in. You could not make this part of the Sheets UI, though.

Google apps script save google spreadsheet to excel version and load it from add-on

Hi I have an idea about file management between GAS and my BDserver. How so? Well, I'd like to have predesigned spreadsheet and save them somehow in my bd. Then users've installed my add-on can load that predesigned spreadsheet on his/her current spreadsheet. PD: Besides the user could save custom "predesigned spreadsheets" for helping to grow the app. How can I save a spreadsheet (Google Drive Spreadsheet) in my server and later call that "file" and load it in a empty spreadsheet? xml? json? export like excel file .xls??. I appreciate your suggestions.
You may find helpful information in Google Apps Script regarding the things that you can do with Google Apps like Docs, Sheets and Forms. You can also find links from the documentation which could help if you've developed a script for Google Sheets and want to share it with the world. App Script lets you publish your script as an add-on so others can install it from the add-on store.
In addition to that, to save your spreadsheet in your own database, you need to connect to it through Apps Script's JDBC service. First, you need to ensure that your database accepts connections from any of Apps Script's IP addresses as detailed in JDBC - Setup for other databases.

Is it possible to integrate Google Spreadsheet into a cloud application and store all app/user data on only one Google Drive account?

Hi Google Drive SDK team on Stackoverflow. I need a personal reply from you guys as this question is important for the backend architecture of a cloud application we are working on.
We want to integrate Google Spreadsheet in the frontend of a cloud application, but we want to structure the backend in such a way that all
user application data/files is stored only on one main Google Drive and not in the user's Google Drive. Does the Google Drive SDK or other Google
products enable the capabilityneed? From the Google Drive SDK page the typical use case is that an app stores data in the user's own Google Drive account.
Our case is different and we want to store all data in our own Google Drive account. Looking forward to your reply. Thanks
https://developers.google.com/drive/v2/reference/files/copy#examples
Its possible but you need to read more about how oauth works and spreadsheet permissions (btw im not from the drive team).
If you will use the users tokens your only option would be to have a backend create the spreadsheet on your drive (with you as the owner) and share it with the user.
If you will use your own tokens and not the user's, you will need a backend to serve as proxy for spreadsheet operations. That way you dont give write permission to the user (so she cant change your data). Drawback of using your own tokens is that you will have quota issues with many users.
The first thing you need to do is decide which API you intend to use.
The link you posted is for the Drive API. This will allow you to upload and download spreadsheets, but not manipulate their contents.
If you require row or cell level access to a spreadsheet, that will use the Spreadsheets API. See https://developers.google.com/google-apps/spreadsheets/
Next decide how you will deal with permissions. You want a centrally owned spreadsheet, so you have three choices.
Proxy all of the access through a web server as suggested by #zig
Access the spreadsheet directly, but use a centrally provided access token
Use a Service Account