Every new copy of my Google Apps Script counts as a different client to Google Cloud, even though my code is in a library they each are sharing. I'd therefore like to specify my own oauth client created within the Google Cloud project, using its consent screen similar to before.
I know how to create said client, but I don't know how to get the consumers of my library (the scripts that call it and their containers) to all use the same client.
How would I accomplish this?
Edit:
Scenario: Script A is a library that needs to oauth authenticate. Script B is a consumer of that library attached to a spreadsheet C. Copies of that Spreadsheet C are counting as new clients. I would like them to use the same oauth client id.
Related
I'm new to apps scripting and have created a web app which is container bound to a spreadsheet.
The app provides an html form for patients to record blood pressure readings as they take them during the day. A query string on the web app url identifies the individual patient and puts their readings on a sheet, unique to them, as they submit them. The script is deployed as a web app (Publish -> Deploy as web app) and in my development account it works well.
Now I want to share the script with a few other accounts not in my domain, so that they can use it independently with their own patients, with their own web app url, with readings going onto their own spreadsheet and for me to be able to maintain the code centrally.
Researching this I see official addons are now provided through the Gsuite Marketplace. It appears my choices for 'sharing' are these:
create an officially reviewed addon and put it in the Gsuite marketplace but creating an addon for the world is not what I want to do (atm anyway!)
create a private addon for inside one domain but I want to share it with several domains
there appears to be a system for testing the script as an add-on, without publishing it and for sharing the testing but this is mentioned in the Gsuite addon docs but not mentioned in the Editor addon docs and anyway it's for testing.
share the spreadsheet in my account but then all readings end up on my spreadsheet
share the spreadsheet and code to other accounts so they can make a copy but then I can't maintain the code centrally
Can anyone suggest the best way to share this web app script so other accounts not inside my domain can use it independently but ideally so I can maintain the code centrally? Thank you.
I see two solutions here. One is to add a small amount of "user management" code to your tool. For example, include some query parameters on your base url such as email and authorization key. Set up a user-management spreadsheet with your list of users, mapping their email to a secret randomly generated authorization key, and their data spreadsheet ID.
When the script is accessed with a valid email/authorization_key combination, it then opens the relevant sheet and does its thing.
In this scenario, you would either need to have access to all the relevant spreadsheets (if the code is executing "as you"), or you would need to figure out a standardised file layout or approach that let your script locate the right files on each users drive (if the code is executing "as the user accessing the web app").
Another solution here is to use an Apps Script Library. Using a library would allow you to keep the bulk of the code in the library, while having lightweight "wrapper" code bound to each of the other users spreadsheets. This wrapper code would simply pass doGet/doPost, and any other function requests back to your library.
For example:
function doGet(e){
return YourLibrary.doGet(e);
}
function doPost(e){
return YourLibrary.doPost(e);
}
function aCallback(a,b,c){
return YourLibrary.aCallback(a,b,c);
}
In the library scenario, each sheet and script can be private to the individual users, you would just need to walk them through the initial setup/deployment, and occasionally have them bump the library version and re-publish the web-app in their copies.
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
I want to retrieve all the user data of my domain in a spreadsheet, so far i am able to retrieve first name email id last name ,storage quota and password change when next time i log in. But I am unable to get details like Apps enabled,License,Contact Sharing,Email Routing - Google Apps Email,Email Routing - Inherit routes , Mobile Devices,Date Snapshot,Date Change,Change Comment,Action done by etc.
I am basically not able to get any API for this all i am getting some JSON or XML codes but what if i entirely want it in GAS only no other files.
Some of what you are looking for is best requested via the Admin SDK. You may want to also check out other Google Data APIs in more detail, you could put together some good reporting tools.
Many of the APIs can be used in Google Apps Script by using the UrlFetch service. There's an OAuth flow built in that service that is quite nice for OAuth 1 flows, and it's not too bad to create a decent Google OAuth 2 flow with UrlFetch as well.
Then you can make authenticated requests to those APIs and handle the responses accordingly with Apps Script.
I am not able to find Adword API support in Google App Script,I can write adword script from adword account but currently i'm handling multiple account(almost 25) what i have to do is go inside individual account and copy my script in that account and adword script have limitation of maximum 15 script can be run by one user at a time, i want to create database of all account at one place that is possible through adword api in java and other programming languages,but i'm quite familiar with Google App script i want to use Adword API in App Script,how can i use UrlFetch() class of Google App Script to use adword api, so that just by replacing client Id of adword account i can get all data at one place(i have access to all account so no need to change username and password).
Thanks in advance for any help and information!
If I understand correctly, the main problem is that you want to to basicaly make a "code library?" So reuse the same bits of code between accounts?
One option is to use the Eval function, as detailed in tip 3 of this article: http://www.ppchero.com/tricks-for-running-adwords-scripts-in-multiple-accounts/. A second example of using this same method is here: http://www.freeadwordsscripts.com/2013/10/use-gdrive-to-load-single-adwords.html
You would then upload this into Google Drive, or point this to the location of the Google Script.
Another option, as detailed in the PPC Hero Article, is to use Google Sheets to pass the variables you need from one script to another. Basically, the SpreadsheetApp function works within all AdWords scripts, so you can use this to pass data along from external sources.
There are some example scripts regarding Adwords associated with these posts:
http://searchengineland.com/four-ways-you-can-benefit-by-using-adwords-scripts-145530
http://googleappsdeveloper.blogspot.co.uk/2012/12/adwords-analysis-in-google-apps-script.html?m=1
I have an app that consists of two parts
an installed application (more specifically: a browser add-on) that runs on the user's machine, and
a web app implemented as a stand-alone Google Apps Script app using HtmlService.
The two parts talk to each other and both access some Google APIs on behalf of the user via Oauth. To do this, I set up an API project in the Google API console. In the section "API Access", I created a client of type "Installed Application" for the browser add-on. For the Apps Script part, Google takes care of the authorization flow automatically.
My problem is that Google does not know that these two clients are part of the same project. Therefore, the user has to go through two authorization steps in a row when executing my app for the first time (first, the Oauth process for the browser add-on and then the automatically generated authorization process from Google Apps Script). This is very confusing to the user, especially, since the splitting between the browser add-on and the web app is rather an implementational detail about which the user shouldn't really have to bother.
Is there a way to unify the two authorization flows? I know that one can add several distinct clients to a single project in the Google API console. It seems to me like this feature is explicitly intended for scenarios similar to mine, where more than one application make up what is perceived as a single service by the user. Unfortunately, web apps that are implemented in Google Apps script don't seem to be compatible with the Google API console because of the way Apps Script generates the authorization flow automatically. Or am I missing an option in the API console or in the Apps Script editor?
For future reference: I found out that Google automatically creates an API project in the Google API console for each Google Apps Script project. This seems to be a fairly recent feature. One difficulty for me was that these API projects don't show up when one goes to the API console, clicks on the name of whatever project is currently opened in the upper left corner and chooses "open". Apparently, the only way to reach the auto-generated API project is as follows:
Go to drive.google.com and open the Google Apps Script project.
Chose "Resources --> Use Google APIs...".
In the popup, click the link to the Google API console.
In principle, this should allow to add additional clients to the project, as long as none of the other clients is also a Google Apps Script project. I haven't been able to test this since it still doesn't solve my specific problem: Sending e-mails from the user's Gmail account seems to be a feature unique to Google Apps Script and I couldn't find an Oauth2 scope for this operation. Therefore, I still cannot ask for all required permissions in a single authorization flow. But if anyone who's reading this has a similar problem with different Oauth2 scopes, the above instructions should fix it for you.
Anyway, I solved my problem in the meantime by no longer using Google Drive to upload files.