403 error from Google Drive direct link due to multiple accounts logged in - google-drive-api

I have a number of images in Google Drive and I am wanting to use them in various ways via the direct link style:
https://drive.google.com/uc?id=DOCID
In Chrome I am logged into three different Google accounts, my corporate one, my personal one, and one other. If I navigate through the Google Drive interface to my files in the corporate account I can see them fine. If I use the form https://drive.google.com/open?id=DOCID then the Google Drive interface opens properly with the image displayed. However, when I try to access the file directly using the uc?id= URL style above I get a 403 error.
"403. That’s an error.
We're sorry, but you do not have access to this page. That’s all we know."
I have tracked this down to being because when I use this URL form, for some reason Chrome or Google Drive are using the wrong authentication credentials - i.e. the ones from my personal account even though this file is in my corporate account.
I've proved this by firing up Firefox, which isn't authenticated to any account, logging in as my corporate user, and then using the URL above: bingo, the image is displayed.
So my question: is there any way to force the URL style above to use the correct set of credentials when accessing the file?

You can use drive.google.com/u/1/uc?id=DOCID or drive.google.com/a/mycorporatedomain.com/uc?id=DOCID
However, do not rely on these URL's not changing in the future.

Log out of all the accounts and only log in just one needed account. This works for me. The google free 15 GB is good since I can always create new email but difficulty in downloading file give drop box an edge.

Related

How to use preview image or PDF from Google Drive, using API?

I'm writting Web application to display content of Google Drive images and files, using API.
Currently, I can only see thumbnails of images/files (without login to Google drive).
If I want to preview the file, I need to be logged into Google drive and then I can use link returned by "webViewLink" and actually see the file.
I know I can click on folder or file on Drive and Share it, but I'm afraid that my customers will not be able to do that and it is complicated, anyway.
I already displaying Google dialog to customer where customer need to allow access to upload,delete etc. of files and now he can not preview the file???
Application is designed to display image/whatever to customer only, inside app only and not to sharing. With other words, I want to display images which he can see anyway if he is logged to Drive.
Is there any other option to allow customer to preview the file, if he already allowed full access previously?
Thanks.
Authorizing with OAuth does not automatically log you in. Users use their credentials to give their permission to create an access token, which needs to be used in any API calls. It does not imply that a browser session was created, that's a separate process.
You'll notice that the webViewLink is just the regular Drive URL with /view at the end. It's a page that requires the user to be signed in:
"webViewLink": "https://drive.google.com/file/d/<FILE-ID>/view?usp=drivesdk",
I'm not aware of any methods to sign in the user at the same time they use OAuth, but if you send your access_token in an Authorization: Bearer <access_token> header when trying to access the above URL you can see the preview without having to sign in. Depending on your platform I think implementing this would be tricky, and maybe not possible in Apps Script alone.
My recommendation as a workaround is to just use a full thumbnail. Don't know if you're aware of this, but the thumbnail URL has a =s parameter at the end that defines its height in pixels:
"thumbnailLink": "https://lh5.googleusercontent.com/<THUMB-ID>=s220",
You can change the default =s220 at the end to a higher size or remove it completely to get pretty much the full size of the image or PDF page. This may be enough for your users to figure out what the file is.

Google Drive Page Not Found - Sorry, unable to open the file at this time

I'm using google scripts to deploy a web app. I've done about 5-10 in the same account. When I try and run the web app/script, I'm now getting: a "Google Drive: Page not found" in the title and the message
Sorry, unable to open the file at this time. Please check the address and try again.
I published it to run as the owner, but accessible to "Anyone, even anonymous".
I then tried creating a new small project with a doGet() method that returns a small static web page, with the same result.
Code.gs:
function doGet(e) {
return HtmlService.createHtmlOutputFromFile('Test');
}
Test.html:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
</head>
<body>
This is a test
</body>
</html>
I tried publishing the same spreadsheet/code above in my personal account and it works fine. Since I already have some web apps deployed with the account that's having the error, is there a quota on the number of web apps per account?
I tried a different browser, a different account, re-publishing, and logging out and back in. Same error message. The "Test your web app with the latest code" link also fails. I can directly call the doGet() method in the IDE and it works fine, and I see output in the logs.
I don't see anything in the logs for the page not found error, which is what I expect with the page not found - not even getting to code execution, thus no logs.
I think you are logged in with two gmail account: That is why (/u/1,/u/0) may have been appended to script address (may be a bug).
So what you have to do is remove /u/0 or whatever is appended.
ForExample:
https://script.google.com/macros/u/1/s/ffffsdds/exec becomes https://script.google.com/macros/s/ffffsdds/exec
I have several Gmail accounts open at once and kept having this problem. I found it helped to close the Drive window, log out of the email account related to it, and then log back into the Gmail account and open Drive again.
You need to add your organization domain to the URL, as in https://script.google.com/a/yourdomain.com/macros/s/ffffsdds/exec - note that a/domain.com has been added. If you're not using a custom domain, use a/gmail.com.
It works when you are logged in to multiple accounts and redirects to
https://script.google.com/macros/s/ffffsdds/exec when you are not logged-in to the particular domain account.
Background info:
https://script.google.com/macros/u/1/s/ffffsdds/exec - does not work if you are logged-in with multiple accounts
In https://script.google.com/macros/s/ffffsdds/exec - "/u/x" has been removed but if you visit that URL, it will still redirect to https://script.google.com/macros/u/1/s/ffffsdds/exec and (1) problem remains when you are logged into multiple accounts (however it works if you are not).
It looks like it's related to this issue: https://issuetracker.google.com/issues/69270374. Authentication is broken for multiple signed-in accounts.
As Google developers suggests, you should:
Signing out of all accounts and using only 1 account: or
Using an incognito tab to sign in
source (comment 292).
What is sad is that, as they said:
The issue originally reported is due to recent improvements in Sheets' ability to handle multiple logged in accounts.
source (comment 11)
So by improving multiple logged in accounts, they also broke it.
Now the "good" news: we can expect this to be fixed in about 1 year I would say.
Our team plans to begin to work on multi-login support for the new Apps Script IDE and container-bound scripts in Q3 ‘21.
source (comment 292)
All the above answers are relevant. But for me, the issue was due to lack of space in Google account. I've used all 15GB space provided by Google and then all my Google Forms started showing the above error.
Solutions are:
Buy extra space from Google, it wont cost much. For 100GB, it costs Rs.130/month or Rs.1300/year
Free up your space. Go through the Google Drive and you may find a lot of unwanted files. Delete it and make some free spaces.

Conditions of using webContentLink?

Which kind of cookie is required to work with webContentLink? I noticed when I'm logged in to Gmail only, i get 403 error. When I open Google Drive too in on other tab and check some files, then my webContentLinks starts to work. Is this the way it should work or did I missed something? Once it was sufficient to be logged in only in Gmail...
(I have a very simple web application, that shows some links to files I shared with my friends in Google Drive. I don't want to use further authentication, but public is also not an option. It was very convenient to have accessible links when their Gmail is opened.)

Cloud Storage Download Appears to Be Malicious

I uploaded a utility in the last few days to google cloud storage.
It's a zip file containing two executables and a readme file.
I tested the download and it worked fine. I then looked into how I could see the download stats and yesterday I enabled logging.
I posted the link to a mailing list this afternoon and clicked it to verify that I had the right link and the download in chrome reports "xxx.zip appears to be malicious".
This did not happen prior to when I enabled logging, but I don't know for sure that is what caused it.
I am using a CNAME alias for the download, and I am a paying google apps customer.
The executables are not malicious in any way. They are simple utilities for doing replacements in text files. They do not access the network at all.
My question is "Why is my zip file being reported as malicious?" and is there any way to remedy this situation?
I looked around for a solution to this problem and I found the following advice:
1) Sign your EXEs. As it turns out, this advice is incorrect. While it has worked for some people, there are people who report that even signed executables are reported as malicious downloads.
2) Use SSL. SSL access is not available for google cloud storage unless you use the commondatastorage.googleapis.com or sandbox.google.com URLs. While this does might work, it doesn't resolve my problem.
3) Use the commondatastorage.googleapis.com URL. This works. The same file using the commondatastorage.googleapis.com url rather than my custom CNAME record does not report that it "appears malicious".
4) Register your site with Google Webmaster Tools. Getting around Chrome's Malicious File Warning According to this stackoverflow entry, the solution is to sign up for Google Webmaster Tools and add your site.
I have tried this one, but it has not made a change just yet. Because this is google cloud storage and not a main site, I added an index.html page, a 404 page, and ran the gsutil commands to enable web configuration within google cloud storage. I added the site to Webmaster Tools and additionally added it to Google Analytics.
I'll give solution 4 a few days to see if it pans out.
It seems like this is more of an issue with Google Chrome and not necessarily Google Cloud Storage. Chrome's methods for identifying malicious files are less than desirable right now.

Google API Service Accounts with Drive SDK

I'm looking for some clarification on accessing Google docs/Drive SDK via a Service Account.
I have everything set up in the API Console and I can successfully generate an access token via the JWT process and indeed I can issue requests to either drive SDK or the Docs List API to get a listing of documents. However, the document listing is always empty, I was expecting to see all the documents in my Google Drive. I am obviously not understanding fully what a service account gives you. If I upload a document via the Service Account then it does show up correctly, but is not visible in my Google Drive, it's as if the Service Account is a totally separate black box.
The reason I want to use Service Accounts is that I have a service running that needs to upload documents to various clients Google Docs accounts, without them having to go through the OAuth dance as there will be no UI interaction at all. Is this possible with Google docs. I was hoping that they could just send my the client_email and the certificate with the private key and I would be able to upload documents to that account.
Many thanks for your consideration
-Marshall
Not sure whether you need the answer anymore, but I just faced with the same issue, came to this post. Found one solution which works in my case, so sharing with everyone here.
The only integration point towards GoogleDrive in my case is document listing.
When I first created my service account, it didn't work as well (just empty list all the time).
What did I do to fix it:
Go to MyDrive UI https://drive.google.com/#my-drive
Checked all the documents I want to see on my website
In the top menu clicked "More"->"Share..."->"Share..."
In "Add people" section (new window "Sharing settings (N items)") I added service account email (format is "XXXXXX##developer.gserviceaccount.com")
Run document listing once again and got it working.