I want to download a Google Sheet (and/or Doc, or Colab Notebook) from an "Anyone can View" sharing URL, if the file is newer than my local copy. To do that, I need to find out when the remote file was last modified. Which I thought shouldn't be hard.
There are threads explaining how to do this for regular files on websites that make use of the HTML Last-Modified property, but Google doesn't provide this field in its headers. It provides a Date: but that's just the download date/time that updates every moment.
I see threads about doing this from within the Doc or Sheet itself. My question is not about that. I'm talking about getting the info remotely by running a python script on my local machine.
I see a thread about using the Google Drive API v3, but....is it really necessary to go through all that (e.g. install oauth, register an API key, etc. effectively create an entire Google app *) just to find out when a publicly-available file was last modified? Is there an easier way?
Thanks!
EDIT: * I started down the road of Google Drive API but I find it confusing and overwhelming. It's like they think I'm trying to create an app for general users for the Android Store, instead of just myself. (??)
Related
I have been running GDrive API v3 using our Node.js API for awhile now (1+ year), and everything has been functional for creating (drive.files.create) & reading (drive.files.get) DOCX files through the Google Drive API logic using a service account. Everything has been working perfectly fine.
Today I am trying to extend our infrastructure to handle some generic Google Docs files (rather than the existing DOCX stored within GDrive) using the same service account, but the GDrive API is now returning a 403 "Forbidden" error for these files specifically. I can't seem to figure out why there would be a difference in permissions for two file formats that are within the same service account (is the owner of both) and are using the same OAuth token system that I set up originally. The service account itself created the file, so I am a little shocked that it can't then access the same file using the GDrive API.
My question is, is it not possible to use GDrive API to access Google Doc files, even when the files are within a GDrive folder? I can't seem to find any definitive information online on whether we specifically have to use the Google Docs API to access Docs files (seems silly if true). If it is possible, is there an alternative SCOPE that I need to assign to this service account to access Google Docs items specifically? Right now the only SCOPE assigned is https://www.googleapis.com/auth/drive, which according to documentation should be enough to access all of our GDrive files.
I can share some code, but there is not exactly a lot more than what I explained above. I would like to not have to entirely re-do my GDrive OAuth permissions if possible, as that took me a long time in the first place, but if that is the only way, I would love to hear suggestions.
Thanks!
I was experimenting with Webextensions earlier this year connecting to scripts in my Google account, but now I cannot determine which script I was connecting to.
So I have the script URL. It looks like a normal script URL, e.g.:
https://script.google.com/macros/s/jG5dForTySatijhf-nmG49F64j62RzkgH6dFgr4SalpUyvF/dev
But I cannot work out which script that URL belongs to! Given a script URL, how do I determine the script in my Google Drive?
UPDATE:
I think I can phrase my question a little better now, and I cannot imagine I am the first person to have this problem so I imagine there must be some solution.
I have the web app URL (like the one above) for a published script. But I cannot remember which actual script (in my Google Drive) it is associated with.
Given a web app URL, how do I determine which file in my Google Drive it is associated with? I know it's one of them but I don't know how to determine which one!
Perhaps I can suggest an alternative approach. This would be particularly useful if you have been experimenting with scripts, as you suggest, and have not created a lot of projects.
All your projects can be found on Google at:
https://script.google.com/home
The metadata for each project includes the name of the container, and you open the container from that screen
I'm trying to implement a shared filespace on an existing server that has its own login/authentication system. I'd prefer if I could use Google Drive or One Drive as the actual backing file store since then the files could (ideally) be edited in browser and automatically update for everyone else that has access to the shared area.
Diagrammatically (red link = existing authorization, red dashed line = desired auth in a session):
The need for this weird scheme stems from usage by a group where almost the entire set of members gets replaced each year (university committee). It was decided we don't just want to use a Google Drive folder since these end up in people's personal Google Drive folders, files get lost of cleared out etc. Additionally we already pass through this website quite regularly so it makes sense as an official repository of committee documents.
However this leaves me stuck with the issue in the diagram. I don't think that the server can create new, temporary tokens for a logged in user for them to pass to the Google Drive API to edit files. The question is really, can I get the Google API to do this for me somehow by only talking to the server? If not, what's the best way to implement this?
Thanks!
We use the Google Drive SDK to monitor a folder of spreadsheets for changes. When a change happens, we download the file to our servers and convert it to JSON for further use.
Since a file may contain multiple sheets, we go through this process to extract all sheets:
Download the embedLink from the drive#file resource and parse the HTML to extract the gid of each sheet. (Similar to the approach used here.)
Download each individual sheet as CSV by appending ?gid=... to the text/csv URL from the exportLinks field.
Recently we've been seeing 429 Too Many Requests errors, especially if the file gets big enough. According to the API console we're not close to the quota limit, so presumably export links are not counted as API requests, but is rate limited some other way. Exporting the sheet manually – as a different user from the one used against the Drive API – works fine.
Is there a way to find the gid of each sheet in a file without downloading the full embedHTML? If not, is there some way to avoid hitting the download limit?
EDIT: This incorrectly closed issue seems to deal with the problem of finding the gids of a spreadsheet file.
UPDATE: I've worked around this issue by parsing the XLSX export instead of the CSVs. Haven't seen the problem since.
I am a little late to the party, but this is for future readers.
Refer to this answer to know why the behavior #felix mentioned is happening.
I am quoting #chrish from the comments.
WARNING: Web hosting support in Google Drive is deprecated. "Beginning August 31, 2015, web hosting in Google Drive for users and developers will be deprecated. Google Apps customers can continue to use this feature for a period of one year until August 31, 2016, when serving content via googledrive.com/host/doc id will be discontinued."
Also, to know more details on the subject, you can read the article Deprecating web hosting support in Google Drive by Google.
Hope it helps.
I am pretty new to Google Drive SDk. After spend hours on the google drive sdk document and quick start app, I think I have known some basic concepts about it.
However, I have a easy but crucial question: how to integrate my code with Drive UI.
I mean I know I should enable Google Drive API and Google Drive SDK and do some configure staff. And I did.
I set up the MIME type that my app should be able to open and create, but it doesn't work. (I used the most easy one: plain/text: txt).
In fact, I think this is not the most serious problem. I am confused about how to integrate my code with Drive UI.
I mean the quick start app works fine, but it just simply upload a file. What if I want to perform some complicate action after user open a certain file with my app?
Ideally, I think it should redirect the user to my open URL and all the actions should go with that site, right?
(I am using Python, in case that could make any differences)
I am really confused. Excuse my chaos description, please.
Thanks in advance!
EDIT:
Thanks for the answering below! I think I need to detailed explain my needs from google drive sdk.
Basically, I want the user who have installed my app be able to open a certain file (which should be spreadsheet or txt) on google drive. Then it will redirect the user to my given Open URL (which I create a site by using google site). On that site, user should be able to view and import the content of file into a certain database. None of the operations above require any technique knowledges. I certainly can do this by writing python script and run it locally to import the content of files on google drive. However, there are two issues: first, I need to run it locally. I mean I did use the google drive api, but I didn't explore the real benefit of api; second, it is still a command line script, and has to be ran on linux.
I hope I have illustrated my request. And I appreciate any help in advance!
Install the client library:
pip install --upgrade google-api-python-client
Acquire an access token as explained on the Python Quickstart example. Init a Drive service to be able to talk to the API and authorize http transporter with your credentials. You need to make requests to get file metadata and file contents.
Retrieve file metadata:
http = httplib2.Http()
http = credentials.authorize(http)
drive_service = build('drive', 'v2', http=http)
f = drive_service.files().get(fileId=file_id).execute()
Retrieve file contents:
downloadUrl = f.get('downloadUrl')
f['content'] = drive_service._http.request(downloadUrl)
(Don't forget content retrieving request should be authorized and authenticated, that's why we use drive_service._http to make that request.