簡體   English   中英

python gspread新手谷歌電子表格

[英]python gspread newbie google spreadsheet

我已經能夠使用適當的憑據成功連接到gspread,但是當我嘗試打開一個existig文件(在我的Google帳戶中)時失敗。 我嘗試過open()以及open_by_key()。 我假設我的帳戶與我剛剛創建的服務帳戶不同,但是我看不到如何手動創建電子表格以進行添加(並最終由python讀取)。

提前致謝

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

在此先感謝您的幫助

您需要做一些事情才能使它起作用。

  1. 從谷歌獲得JSON對象作為記錄在這里
  2. 將工作表從您的帳戶共享到在json對象中創建的電子郵件。
  3. wks = gc.open("My Existing Sheet").sheet1調用中使用電子表格的標題。

如果庫找不到文件,則說明ID不存在或憑據錯誤。 此外,您應該考慮將官方客戶端庫與其電子表格API v4結合使用(此版本比v3更好):

https://developers.google.com/api-client-library/python/start/installation

您還應該檢查驅動器API是否已啟用,但我想是的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM