How to upload file using service account and python - python

I currently have a python code and already created a service account. I now need a way in order to upload file into a google drive folder shared to the service account.
Bonus points is finding first if a certain folder already exists, if not create the folder then upload the file over there.

Check the Google Drive API documentation and specially the Quickstart guide with Python. Also, read this Stack Overflow guide to learn how to write good questions. :D

Related

Ask to user credentials to access Google Drive Api

I'm creating a cli tool to move file around in a user Google Drive space. I'm using Python and Google Drive Api Python SDK to do that and I've created this repo.
Now I have to run every midnight this tool to move file from a folder to another with input from user. Locally I can create credentials.son and retrieve credentials from it, generate the token.json file and use it to authenticate to Drive api. But in public CI environment, I would save my credentials in a Github Secret and give them to my tool at runtime using an option.
Can I do that?
There's some security issues?
I would publish this tool in some forums (like Python SubReddit) to get suggesstions and improvements, but before do that, I'd like to make this move file function as complete as possible.

Fetching Google Sheet data from locally mounted drive via gspread

I am working on a Google Colab notebook that requires the user to mount google drive using the colab.drive python library. They then input relative paths on the local directory tree (/content/drive/... by default on that mount) to files of interest for analysis. Now, I want to use a Google Sheet they can create as a configuration file. There is lots of info on how to authenticate gspread and fetch a sheet from its HTTPS url, but I can't find any info on how to access the .gsheet file using gspread that is already mounted on the local filesystem of the colab runtime.
There are many tutorials using this flow: https://colab.research.google.com/notebooks/io.ipynb#scrollTo=yjrZQUrt6kKj , but I don't want to make the user authenticate twice (having already done so for the initial mount), and i don't want to make them input some files as relative path, some as HTTPS URL.
I had thought this would be quite like using gspread to work with google sheets that I might have on my locally mounted drive as well. But, I haven't seen this workflow anywhere either. Any pointers in that direction might help me out as well.
Thank you!
Instead of adding .gsheet on colab's drive you can try storing it in the user's drive and later fetch from there when needed. So until that kernel is running you won't have to re-authenticate the user.
I'm also not finding anything to authenticate into colab from other device. So you would consider modifying your flow a bit.

Can I edit an excel file on onedrive using python?

I have been searching for hours trying to find out how I could edit an Excel file saved to OneDrive using python and have had no luck. Help if you know how/if it is possible.
#JeremiahTrest Welcome to Stackoverflow. I don't think that's how OneDrive works. What I mean is, I don't think it's possible to directly edit a file that is saved to your OneDrive in the cloud with any language. What you would have to do is to get a copy of the file on the machine that is running the Python script, update the file on that machine and save it with the changes, then push the changed file to your OneDrive. I looked and found this SDK for Python that is meant to be able to help you interface with the OneDrive API. So, you would use this SDK to get the file from OneDrive, update the file locally, then use the SDK to push the changed file back out to OneDrive.
I came across this post as I have the same task. Here's what I'm going to try:
Use the request library on python to call the OneDrive API.
Here's the page on excel APIs:
enter link description here
I'll update when I have my code.

how to allow my own google drive app to only upload files

I want to develop a backup app, I wish that the app will be able only to upload files without any permissions to delete files (or any other permission).
is it possible ?
Yes, it's possible. Start by looking for a python library that lets you communicate with the Google Drive API. See Google APIs Client Library and PyDrive (you'll find easy code as example here).

How can I use Google documents list APIs with the none-document files such as .jpeg .gif?

I'm now using gdata-python-client(Google document List API) to access my google drive on Terminal in Linux OS and I have problem to show the image files -- It's just show only the .doc .xls or .pdf files
Is it has some solutions to solve my problem in still using gdata-python-client? I hope there is some solutions better than changing my APIs to Google drive API,that's mean I should restart my project!!. So sad :(
And If I change to use Google Drive APIs.how to do it? or can i reuse my project working compatibility with the new APIs?
Please give me some advice or tutorial.
Thank you very very very much :)
Use the Drive API. We have a Python command line sample to get you started, and python snippets for every API method including files.list.

Categories