The OAuth 2 hint was a good one. I found PyDrive.
From the docs of PyDrive:
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.
- On ‘Services’ menu, turn Drive API on.
- On ‘API Access’ menu, create OAuth2.0 client ID.
- Select ‘Application type’ to be Web application.
- Input
http://localhost:8080/ for both ‘Redirect URIs’ and ‘JavaScript origins’. - Click ‘Download JSON’ on the right side of Client ID to download client_secrets.json
client_secrets.json is the file that has all authentication information of your application. Put this file in your working directory.
from pydrive.auth import GoogleAuth gauth = GoogleAuth() gauth.LocalWebserverAuth() # Creates local webserver and auto handles authentication
Run this code and you will see a web browser asking you for authentication. Click Accept and you are done with authentication. For more details, take a look at documentation: OAuth made easy.
auth.py, than just import it in your main file. And never shareauth.pyClientLoginis only one of the authentication mechanisms, and not the usual one you want to use. You can also useAuthSub,OAuth, or (usually the best)OAuth 2. Read more of the documentation than just the hello world example, e.g., Authorizing Requests in the Google Spreadsheets documentation.