After 2 days of reading gspread docs, gspread blog posts, and following the most recent docs for using gspread I'm still not able to open even one Google Spreadsheet. I set up a GDrive API service account. It appears that my OAuth2 credentials are working, but I'm still getting constant 'SpreadsheetNotFound' errors.
My code looks something like this, and runs with no error message until it tries to open the Google Spreadsheet:
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
jsonfile = '/path/Python-data-GSpreadsheets-dbbc-99.json'
credentials = ServiceAccountCredentials.from_json_keyfile_name(jsonfile,scope)
# get authorized to access data
gc = gspread.authorize(credentials)
# gc returns with no error messages, so far OK
wks = gc.open('SSTEst123').sheet1 #fails here
#throws SpreadsheetNotFound error
Yes, I've added my gmail email address as authorized to edit (tried it with and without) since the service account should be able to access all my data anyway, and I'm resharing my spreadsheet with myself.
What else can I try to discover why it is failing? Any ideas on how to debug why it can't open any spreadsheet?
OK, here's how I solved it. Had to share my spreadsheets with the Google Drive API service account 'email address' (e.g. my.test.data@python-xyz-gspreadsheets.iam.gserviceaccount.com ) -- (Thought it was my 'real' gmail ID/email, but it wasn't)
For debugging the feed ... Added a few print() lines in the gspread client.py source to see if I was getting anything in the feed, and to check the values from the feed. Noticed that I was getting a value that was old value (from previous script?)
Shut down and restarted my iPython notebook, and it's working now.