2

I have a publicly available dataset hosted in a Google Spreadsheet.

I can open that from my Colab notebook using gspread as follows:

import gspread
from oauth2client.client import GoogleCredentials


gc = gspread.authorize(GoogleCredentials.get_application_default())
worksheet = gc.open_by_url('https://docs.google.com/spreadsheets/d/1pwb4gf0FxlxgfVhtXTaqEGS9b7FwsstsJ0v7Zb1naQ0').sheet1

However this prompts me to log in with my google credentials when I run it. I would like to read the spreadsheet without needing to enter my credentials, given that the spreadsheet is public.

How can I do that?

Jsevillamol
  • 2,425
  • 2
  • 23
  • 46

1 Answers1

1

Save your service account json keyfile on your personal drive. In colab, click the "files" symbol (In the left column-menu) and mount google drive. I am not sure if it is safe(?).

import gspread
from oauth2client.service_account import ServiceAccountCredentials
creds = ServiceAccountCredentials.from_json_keyfile_name(
            pathandyourKeyFileOnGDrive.json,
            scopes=[
                'https://www.googleapis.com/auth/drive',

            ])


gc = gspread.authorize(creds)
worksheet = gc.open("myTable").sheet1
Servus
  • 479
  • 3
  • 13