Sharing a script to everyone with link raises an Internal error - google-apps-script

I'm trying to share a script via Library.
I publish a library using "Manage versions", but when I navigate to "File" > "Share", and trying to gain read access to "Anyone who has the link", I got an "Sorry, an internal error has occurred and your request was not completed." while saving.
Any way to fix this?
P.S. I try to do it in 2 accounts.

Answer:
Permissions for a script that is bound to a Drive file must be the same as the permissions of the file to which it is bound. Make sure that the permissions are set on the file first, and then you can get the share link for the script using the same permission settings for sharing.

Related

How can I restore permissions for Chrome to access any local files from VS Code?

Now, every time I try to open my html file in my Chrome browser, I get this message:
ERR_ACCESS_DENIED
Can someone please tell me how I can reverse this?
How do I grant Chrome the permission to access any local files on my VS Code and atom?
Now, Thanks to Kuma, check out the thread link he or she provided, which helped me. You just have to go to system preferences, and under security and privacy, go to filers and folders, and go to files and folders and check the check box next to chrome.
If you are on a Mac, you can try the following:
Run the the following command on the file in a terminal, then try to open it again:
xattr 'your .html file name'
# If it shows com.apple.quarantine, run
xattr -c 'your html file name'
If that fixes it then it's most likely some apple security metadata on the file that get attached when files are downloaded from the web.
If you are on Windows10, you can view all the permissions you have added and rejected for an app (see this link: https://www.google.com/amp/s/www.howtogeek.com/368598/how-to-manage-app-permissions-on-windows-10/amp/)
Extract:
From the Settings screen, you can head to Settings > Apps > Apps & Features, click an app, and click “Advanced Options.”
Scroll down, and you’ll see the permissions the app can use under “App Permissions.” Toggle the app permissions on or off to allow or disallow access.
Otherwise, knowing what OS you are using will help find a solution.
There is also this other stack overflow thread, so you can try some of the answers there: Can't open some html files in chrome (mac)

what client_secret.json file is it required for google drive files access

I am getting this error:
File "/usr/local/lib/python3.7/site-packages/pydrive/auth.py", line 388, in LoadClientConfigFile
raise InvalidConfigError('Invalid client secrets file %s' % error)
pydrive.settings.InvalidConfigError: Invalid client secrets file ('Error opening file', 'client_secrets.json', 'No such file or directory', 2)
all I want is to list files and folders using pydrive !
I tried creating credentials but On consent page its showing unverified status.
from the credential page under OAuth 2.0 Client IDs tab I downloaded created credentials and downloaded crediential file secret_json_[.....].json file
Looking into the documentation for pyDrive:
Click ‘Download JSON’ on the right side of Client ID to download client_secret_<really long ID>.json.
The downloaded file has all authentication information of your application. Rename the file to client_secrets.json and place it in your working directory.
So probably you are lacking the last step of renaming the file and placing it in the working directory.
I tried creating credentials but On consent page its showing unverified status.
This should not matter at all, unverified just means that you are trying to access sensitive scopes and until Google verifies your application there would be an extra screen indicating that it is a unverified apps. Is okay for personal/development use.

CLASP Local Login

I'm trying to figure out how to set up a local login file for my google scripts project in order to set it up so it'll work in an automated deploy process.
As far as I can tell, clasp login will create a file in your home directory which authenticates you with scripts.google.com, but that file isn't applicable to to local logins because it's missing some properties like "project_id".
When looking for how to create a file to run with clasp login --creds {file} there doesn't seem to be a straight forward way to generate one of those files in your local directory, which is how I would like to set up my deployment pipeline.
Most of the documentation on the internet says that you can create your own file by navigating to your GCP project and exporting a service account json file, but I don't know how to tell which GCP project my google script project is associated with.
I'm super lost, any help would be appreciated.
Thanks,
Alex
In order to log in locally I performed these steps:
In your project, make sure it's associated with a project id
(in the legacy editor > resources > cloud platform project > set your project id)
Then go to https://console.cloud.google.com/apis/credentials?authuser=0&project=your-project-id, create an Oauth2.0 clientid, and download your client secret and save it locally
From there you can locally log in by running clasp login -creds /path/to/file
Thanks to ALE13 and Error retrieving access token: TypeError: Cannot read property 'project_id' of undefined

Reauthenticate or Remove authentication Pydrive during runtime in Google Colab

I want to reauthenticate my Google Drive Credentials so that I can login from a different Google account and access it using pydrive. How can I do that?
I am using the following code to authenticate:
auth.authenticate_user()
gauth = GoogleAuth()
gauth.credentials = GoogleCredentials.get_application_default()
drive = GoogleDrive(auth = gauth)
I want to get a fresh token and option to login again into a different google account?
Thanks for helping!
Try deleting the credential file produced by auth.authenticate_user() based on the auth module
rm /content/adc.json
I have just found a solution to this issue. If one goes to his/hers Google Account Settings->Security->Signing in to other sites(all the way down)->YOUR PROCESS NAME and then simply remove it. If you try simply listing the files in the authenticated drive again it should fail with "Token has been expired or revoked."
Just make sure when you create and enter your correct account credentials to delete the credentials/client_secret.json file as the settings.yaml does not seem to overwrite
To reset credentials just remove the gdrive config folder with a shell command from a code block
rm ~/.config/Google/DriveFS/ -rf
I ran into a similar problem where I clicked on the wrong account for Google Drive authentication. None of the files I needed to access were available, and I couldn't figure out a way to revoke a token by the comments above. I tried both restarting the runtime and changing from GPU to TPU. When I tried the latter, it worked and the authorization prompt returned. However, I'm not sure if it worked or just reached the token refresh time.
I factory reset my runtime and was able to get it to accept a different credential.
Runtime -> factory reset runtime

Google Drive DriveCommandLine sample app not working?

Is the Google Drive API sample command line app (DriveCommandLine) currently known to work? I have downloaded the Java client library, and compiled the sample application (inserting my application's client ID and secret created by specifying "installed application" and "other"). It runs and informs me to access the following link in a browser:
https://accounts.google.com/o/oauth2/auth?access_type=online&approval_prompt=auto&client_id=MY_ACTUAL_CLIENT_ID&redirect_uri=urn:ietf:wg:oauth:2.0:oob&response_type=code&scope=https://www.googleapis.com/auth/drive
(Obviously with my actual client ID there.)
This successfully provides me with an authentication code. When I enter this at the application's prompt, then at the line:
File file = service.files().insert(body, mediaContent).execute();
I get the exception:
Exception in thread "main" com.google.api.client.http.HttpResponseException: 401 Unauthorized
at com.google.api.client.http.HttpRequest.execute(HttpRequest.java:978)
at com.google.api.client.googleapis.media.MediaHttpUploader.executeUploadInitiation(MediaHttpUploader.java:338)
at com.google.api.client.googleapis.media.MediaHttpUploader.upload(MediaHttpUploader.java:252)
at com.google.api.services.drive.Drive$Files$Insert.executeUnparsed(Drive.java:309)
at com.google.api.services.drive.Drive$Files$Insert.execute(Drive.java:331)
at DriveCommandLine.main(DriveCommandLine.java:56)
Investigation shows that the GoogleCredential returned has all elements set to null (which seems wrong).
The version of the Drive API client that I am using is "v2-rev5-1.7.2-beta", which is the one currently pointed to on the quickstart page here:
https://developers.google.com/drive/quickstart
I am compiling and running with this JAR and all the ones in the "libs" subdirectory in the classpath (the quickstart page refers to adding source JARs to the classpath which, obviously, dosn't work).
Can anyone shed any light on what might be going wrong here?
Thanks!
The link in the Quick Start is outdated. Try downloading the Drive SDK from the following link: http://code.google.com/p/google-api-java-client/wiki/APIs#Drive_API
See if that makes a difference for you. I have the DriveCommandLine app running fine.
You need to download JSON file from the API access page at
https://cloud.google.com/console.
Rename this json file as "client_secrets.json"
Copy this json into your project folder or more specifically copy it
into "src/main/resources". (This file contains the clientID and secrets). If the file is already present in the folder then replace it.
Now run the project. You will be redirect to Google Drive's "allow
access" page.
PS - json file must belong to an "Installed Type Application" because this is a commandline sample and runs locally.