[英]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
在此先感谢您的帮助
您需要做一些事情才能使它起作用。
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.