So with the google sheets api, I can use a credentials json file to edit a google sheet. I don't have to login again and again. Is it possible to do this same thing with the google drive api? I am making a Python webapp, and it is very inefficient to need to log into a google account every time I want to upload a file. I plan on only uploading files to one drive, and not multiple accounts. I have looked on stack overflow a couple times, and can only find documentation on how to login with a user account and this requires I login every time.
Best wishes,
Jake
You can do the same thing as in Sheets, follow the official Python Quickstart from the docs for instructions on how to do it.
Related
Actually I'm doing a attendance management system which gets the users Id, in time and uploads it to google sheet. Now the catch is inorder to write in google sheet we need internet, I know I can use Microsoft excel instead, But for certain reason I need to use Google sheets (because it includes a google script). Now I need to know whether I can write to google sheets without the internet or not!!
I understand that you want offline access to Sheets using Python. If I understood the situation correctly, you only need to give an eye to this guide about OAuth 2.0 for Desktop Apps, especially the part about calling Google APIs. Please, ask me any doubts about this approach.
Can I read a google spreadsheet which is open to people, but doesn't have a share option? There's a discussion here, but it's I need to have an authorization to click the share option.
Even copying by URL to my own Google spreadsheet may serve the purpose.
Update:
The idea was once I create a Google API, I should be able to create a .json file with a client email. In the share option, I'm supposed to provide the client email of .json file. You may see: Accessing Google Spreadsheet Data using Python.
This is the spreadsheet page where I'm not finding any Share option: https://docs.google.com/spreadsheets/d/e/2PACX-1vSc_2y5N0I67wDU38DjDh35IZSIS30rQf7_NYZhtYYGU1jJYT6_kDx4YpF-qw0LSlGsBYP8pqM_a1Pd/pubhtml#
Issue:
Publishing the contents of a spreadsheet to the web is not the same as making a spreadsheet public.
The URL you shared refers to spreadsheet contents that were published to the web following these steps. This published website is not the same as the original file where the data comes from, and so it doesn't have most of its functionalities, like a Share button (it doesn't make sense to have a Share button anyway, since this URL is already public).
Solution:
If you want to access the spreadsheet data using a Service Account, you would have to do one of the following (better to use method 1 if you have access to the spreadsheet):
Share the spreadsheet itself (not the published contents) with the Service Account, as explained in the link you referenced.
Use your application to fetch the website contents from the provided URL.
Reference:
Make Google Docs, Sheets, Slides & Forms public
I have an access to the not-mine private spreadsheet on the Google Sheet. When I access to that spreadsheet from browser, everything is fine. But, when I try to retrieve the content of that spreadsheet through Google Sheets API using Python, I am getting 403 error - "The caller does not have permission".
The problem is I can not ask the owner to give me one more permission for my API.
Can I retrieve the content of that spreadsheet somehow? Maybe using some tools?
You prolly can access it because you got the link from someone. But to access it using the API will require you to be added in the permissions. Worth checking would be this Google Drive SDK: Sharing Files tutorial video and the Permissions docs.
I am using gspread to collect data from several hundred Google Sheets spreadsheets. I parse the files stored by Google Drive in a local directory and obtain the URLs for all the spreadsheets within a specified folder. Then I use a python wrapper to go through the URLs and a shell script wrapper to jump start the python wrapper when the connection glitches out.
One of the causes for the glitches is the SpreadsheetNotFound error. I did a quick check about halfway through and found that 21/139 (~15%) of my spreadsheets always get this error (I have it skip the spreadsheet if it's not found five times). I have gone in with iPython and manually tested these with open_by_url, open_by_key, and open (with the title), but they all return the same SpreadsheetNotFound error. The most frustrating part is being able to copy the URL directly from my error message, pasting it in the browser, and the browser going straight to the spreadsheet without a problem. The second most frustrating part is that it works beautifully for ~85% of the spreadsheets, but 85% is not exactly going to cut it.
I'm not even sure this is solvable. I'm just curious if anyone else out there has had this problem with gspread.
Thanks for any feedback.
Edit 1: Hm, the failing spreadsheets were all created prior to 2/2/15. The older sheets have been updated to the newest version of Drive - that may have had an effect on the API.
From the Gspread docs:
ClientLogin is deprecated:
https://developers.google.com/identity/protocols/AuthForInstalledApps?csw=1
Authorization with email and password will stop working on April 20, 2015.
Please use oAuth2 authorization instead:
http://gspread.readthedocs.org/en/latest/oauth2.html
So I assume you're using oAuth2. Which means you need to add the email address in that json cert file to the spreadsheet.
Using OAuth2 for Authorization
See point #7:
Go to Google Sheets and share your spreadsheet with an email you have
in your json_key['client_email']. Otherwise you’ll get a
SpreadsheetNotFound exception when trying to open it.
Is there any way to upload files to another user's Google Drive without asking for login or verification code each time except the first time?
Until now I used pydrive, but it asks to login each time. Is there anyway other than this, such that a key or something to use to skip the login of the user?
To clarify: you want to enable others to upload files into your own Google Drive? If that is the case, you can do this with this embed widget that you can copy & paste into your website: http://developers.cloudwok.com
If you want to allow users to upload files to a random Google Drive account of some other user, that won't work because the other user must give permission.