3

I am following this guide by google, on how to access a spreadsheet with a python library. But: Then I have to write my google username and password without encryption in a python script, which is a huge security issue for me, especially, when you give the script away to others.

So: Is there a way to write to a (public) Google spreadsheet with python without providing a username & password?

Downloading data from there is possible.

2
  • Move your secret data to external file, e.g. auth.py, than just import it in your main file. And never share auth.py Commented Aug 27, 2014 at 10:56
  • ClientLogin is only one of the authentication mechanisms, and not the usual one you want to use. You can also use AuthSub, 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. Commented Aug 27, 2014 at 11:07

1 Answer 1

1

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.

  1. Go to APIs Console and make your own project.
  2. On ‘Services’ menu, turn Drive API on.
  3. On ‘API Access’ menu, create OAuth2.0 client ID.
  4. Select ‘Application type’ to be Web application.
  5. Input http://localhost:8080/ for both ‘Redirect URIs’ and ‘JavaScript origins’.
  6. 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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.