我已经能够成功连接到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