【发布时间】:2016-11-21 10:19:40
【问题描述】:
我正在构建一个 python 应用程序,用户可以在其中提供“任何人都可以编辑”链接到他们的电子表格,并且可以从那里读取数据。我正在使用 python 的 gspread 模块,但它会引发 SpreadSheetNotFound 错误。
import gspread
from oauth2client.service_account import ServiceAccountCredentials
scope = ['https://spreadsheets.google.com/feeds']
credentials = ServiceAccountCredentials.from_json_keyfile_name('myauth.json', scope)
gc = gspread.authorize(credentials)
wks = gc.open_by_url(urls_given_by_user_having_edit_permission)
以上代码不工作。有什么方法可以实现吗?
【问题讨论】:
-
你能分享
urls_given_by_user_having_edit_permission的格式吗?只是为了给出一个值的一般概念。如果你想隐藏真正的价值,你可以省略一些字符。 -
@Burnash 类似于docs.google.com/spreadsheets/d/…,其中 d/ 之后的值是键。我正在寻找任何方法来完成上述任务,而不是对 gspread 严格。
-
您是否尝试按键打开电子表格? github.com/burnash/gspread#opening-a-spreadsheet
-
另一种可能的解决方案是通过 json 接口访问您的电子表格:spreadsheets.google.com/feeds/list/<PUT-KEY-HERE>/od6/… 用于列表,spreadsheets.google.com/feeds/cells/<PUT-KEY-HERE>/od6/… 用于单元格
-
@Burnash by key 从 url 中提取密钥,仅此而已,但效果不佳。提要会从自己的帐户中提供电子表格,不是吗?我正在寻找访问具有编辑权限共享的另一个用户的文档。
标签: python google-sheets gspread