我已經能夠成功連接到gspread與適當的憑據,但當我嘗試打開一個existig文件(在我的谷歌帳戶)失敗。我已經嘗試open()以及open_by_key()。我假設我的帳戶與剛剛創建的服務帳戶不同,但我看不到如何手動創建電子表格以添加(並最終由python讀取)。蟒蛇gspread新手谷歌電子表格
在此先感謝
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name("MyCreds.json", scope)
gc = gspread.authorize(credentials)
# Does not work (Spreadsheet not found):
wks = gc.open("My Existing Sheet").sheet1
Does not work (Spreadsheet not found):
wks = gc.open_by_url("https://docs.google.com/spreadsheets/d/16H7OZohbLmRoe1zZzb5ek5KZnLQKMGA-ZqyfnBms7OI/edit#gid=0").sheet1
# Does not work (Spreadsheet not found):
wks = gc.open_by_key("16H7OZohbLmRoe1zZzb5ek5KZnLQKMGA-ZqyfnBms7OI").sheet1
在此先感謝您的幫助
我知道我試圖訪問的文件確實存在於我的個人帳戶中,因爲我可以在Google工作表中訪問它。我從我的個人帳戶創建了憑據。假設我的憑證是正確的,我該如何/在哪裏編輯一個電子表格,我可以以編程方式訪問? – jordanthompson
所以我取得了一些進展(我認爲)。似乎您需要在設置憑據時使用json文件中的client_email共享您的個人表單。我分享了它,但仍然得到了SpreadsheetNotFound異常,並帶有所有三種不同的打開命令。順便說一句,我使用的是從pip安裝得到的最新API --upgrade google-api-python-client – jordanthompson
我可以看到你已經爲這個問題添加了一個答案。你現在能打開電子表格嗎? – Burnash