-
Notifications
You must be signed in to change notification settings - Fork 0
Python Access to Google Drive
Google Drive's web interface sucks and is terrible for uploading/downloading/browsing large datasets and files.
Install the latest version of our custom python package gdrive-access. Follow the link for installation and usage instructions.
pip install git+https://github.com/theunissenlab/[email protected]
Here are specific instructions on getting google drive API credentials if you want to do things yourself or need more functionality than gdrive-access is giving you (although you can always just add what you need to gdrive-access instead!).
To do this, we will use pydrive, which lets you use python objects and functions. However, the way to get this set up is very annoying (setting up authentication). I will describe how to get this set up (tutorial good as of Jun 2019).
- Install pydrive (lets you make requests to google API through python)
- Create local settings and credentials files (so you do not have to repeatedly give access whenever you run your code)
- Create Google API Credentials (your "app" that will access your drive data)
pip install pydrive
In your project folder (where you will run your python code from), create the following files
client_secrets.json
credentials.json
settings.yaml
The first two should be empty. The third should look like this:
client_config_backend: settings
client_config:
client_id:
client_secret:
save_credentials: True
save_credentials_backend: file
save_credentials_file: credentials.json
get_refresh_token: True
(We will fill in the client_id and client_secret soon)
The following instructions are copied from the pydrive documentation here: https://pythonhosted.org/PyDrive/quickstart.html
Its a little confusing, but at the end of this, you should have a client_secrets.json
file in your project's directory, and have opened up a browser window asking for your permission to access your data.
When you download the client_secrets.json file, replace the empty file you created above, and copy the client_id and client_secret from that file into your settings.yaml file
Drive API requires OAuth2.0 for authentication. PyDrive makes your life much easier by handling complex authentication steps for you.
- Go to APIs Console and make your own project.
- Search for 'Google Drive API', select the entry, and click 'Enable'.
- Select 'Credentials' from the left menu, click 'Create Credentials', select 'OAuth client ID'.
- Now, the product name and consent screen need to be set -> click 'Configure consent screen' and follow the instructions. Once finished:
a. Select 'Application type' to be Web application. b. Enter an appropriate name. c. Input http://localhost:8080 for 'Authorized JavaScript origins'. d. Input http://localhost:8080/ for 'Authorized redirect URIs'. e. Click 'Save'.
- Click 'Download JSON' on the right side of Client ID to download client_secret_.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.
Create quickstart.py file and copy and paste the following code.
from pydrive.auth import GoogleAuth
gauth = GoogleAuth()
gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication.
Okay, so the above should have created a browser window, and the settings file should have made it so that your credentials are stored locally in credentials.json, so you do not have to repeatedly log in with the browser window anymore.
Now, in python you can create a drive object with
from pydrive.auth import GoogleAuth
from pydrive.drive import GoogleDrive
def get_auth():
gauth = GoogleAuth()
gauth.LocalWebserverAuth()
return gauth
drive = GoogleDrive(get_auth())
Tada
Calendars and scheduling
Lab funds and purchases
Advising, Social Justice, Sexual Harassment, and Real World Shit
* Support ResourcesGetting connected to the lab network
Data storage and access
Computing
Working Remotely
Other Services
Husbandry, who to call, recordkeeping
Bird care links
Pecking Test (NAF 125)
Field Station
Protocols, "how to"s, techniques, and recipes
Instructions for individual pieces of equipment
Instructions
Hardware, software, and techniques for ephys
Data Collection
Data Analysis
Old pages:
- Webcam Notes
- Arduino Notes
- Pecking test computer configuration
- Troubleshooting (pecking test)
- Pumpkin's Sound Card
- Preparing Stimuli
Pages in progress: