How to capture google account of viewer using google apps script? [duplicate] - google-chrome

This question already has an answer here:
Getting a list of active file viewers with apps script
(1 answer)
Closed 1 year ago.
So i have a google sheet table to store data of my team (name and gmail account). I will assign every user with different task in my project. I create a web app (user interface) using apps script so my user can interact with the task. In this case, assumes all my users will be using google chrome browser and need to login to the google account on their own browser. For users who use other browser or if not sign in to google account will be ignored.
If i deploy my apps script, is there any method to know which user is browsing it just by checking the google account they use. I don't want to create custom user/pass to login. I just want the script can detect by active google account to personalize the page so they don't need to see all available the task but only can see specific task that they are assigned to.

https://stackoverflow.com/a/66342797/16125139
This should help you
Session.getActiveUser().getEmail()

Related

How to launch Google App Script from external [duplicate]

This question already has answers here:
Can not run trivial app script bound to new blank document - get "This app is blocked"
(3 answers)
Closed 5 months ago.
I have created a custom function in a Google Sheet and I have given access to the Sheet to other users. But unfortunately the security settings of there company do not allow the users to unlock this script for their account.
This app is blocked. This app has tried to access confidential data in your Google account. To protect your account, we have blocked the access.
Is there any way that users can still run this script externally without having to install it themselves? So for example via a click on a button, which then starts the script in my account.
No, you won't be able to do that. The only way some code could be triggered by external users, but effectively executed by your account, would be in an apps script web app.
As you can see in the screenshot, there's an "Execute as" setting when you deploy an app that controls this behaviour:
I appreciate that this may not be an option for you, given that the current code is a custom function in a sheet. The only other approach would be to have the external users make a copy of the sheet, with its function(s), to run in their Google Workspace environment.

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.

How do I know a gmail account is a member of Google Groups?

I am creating a web app with Google Apps Script.
I want to know if an app user is a member of Google Groups.
Group site: https://groups.google.com/
It is not groups managed by G suite.
Create a Google spreadsheet.
Open this and add the group's email in the sharing task.
When I open a file shared by a group in a script and open it, can I verify that it is a member of the group?
What's available from Google's API is the Members.list.
Retrieves a paginated list of all members in a group.
Give it a try.
Haven't really tried it but the Apps Script version seems to be getUsers().
I don't believe this is possible. This is information you would have to get when the script executes. When the script runs, the Active User (Session.getActiveUser()) is the script owner (you), and the user returned by Session.getEffectiveUser() won't allow you to get the email address. More information at:
https://developers.google.com/apps-script/reference/base/user#getemail
Basically, this would only work on a G Suite domain.

Google Scripts adding viewers to a file, causes email sent [duplicate]

This question already has answers here:
Share a Drive document without notifying user with Google Apps Script
(3 answers)
Closed 5 years ago.
I have a google-appmaker project where I add the list of possible viewers down the workflow chain to a file. Once the user attaches a file and starts the workflow, I take the attached file and the viewers down the chain to it so that they can view it.
However when I use it, it also sends another email to the user, and the viewers that the file is shared. Ideally I'd like to add them without triggering the email since there is also another email that goes when the workflow starts. Is there a way to add viewers without notifying them file.addViewers doc.
Thanks
This can be done using the advanced Drive API.
Documentation is here
and code goes like this :
function testFileSharing() {
shareFile("14fQ#################9SW2SIIutz5qk");
}
function shareFile(ID){
var permission = Drive.Permissions.insert({value:"test#gmail.com",role:"reader",type:"user"},ID,{sendNotificationEmails:false,emailMessage:"testing for you"});
Logger.log(JSON.stringify(permission));
}
The advanced Drive API must be enabled in the ressources menu and in the Google API Console.

Cancel Gmail Meter Apps Script trigger [duplicate]

This question already has answers here:
How do I deactivate GMail meter emails?
(3 answers)
Closed 7 years ago.
Two years ago I installed the Gmail Meter on my G-mail account. It provides me reports monthly. Since I'm not aware about managing the triggers and this stuff, I have no idea how and where I could stop or cancel that trigger.
Can you give me a clue?
You can see all your triggers by opening up the script editor. Do you have any Apps Script files in your Drive?
Google Drive
If you do, open up an Apps Script, and in the script editor, choose the RESOURCES menu, and the ALL YOUR TRIGGERS menu item. You can review, and delete all your triggers there.
The Gmail Meter documentation states that you received an email when you signed up, and that email has a link to uninstall the app. Did you go through that process?
Also, go into your Google Account,
Link To Google Settings Page
and view all your connected apps.
Revoke Access to any App that you don't want any more.
Also go into your security checkup:
and remove anything that you don't want anymore.
The Gmail Meter documentation also states:
Lastly, simply delete the file in your Google Docs/Drive that is used for storing the Gmail Meter data: "Gmail Meter Data - Do not delete".
Try signing up to the platform again here http://www.gmailmeter.com/#sthash.YeNkVmQn.dpbs and then cancel the script through the official link when the confirmation mail arrives here.
Go to account.google.com
Then log in using your Google Account.
Now scroll down to find the "Account Permissions" and select it.
Now find the Gmail Meter, select it and choose Revoke Access from the top right corner.