我刚开始使用Gspread,并试图在我的谷歌驱动器中访问我的一个Google文档电子表格。我按照说明进入了Google API控制台并创建了一个JSON文件。当我运行此代码时,我得到不出错:使用Python Gspread访问Google Drive电子表格
import gspread
import json
from oauth2client.client import SignedJwtAssertionCredentials
json_key = json.load(open("mwsSearch-b3d5d5d9c956.json"))
scope = ["https://spreadsheets.google.com/feeds"]
credentials = SignedJwtAssertionCredentials(json_key['client_email'], bytes(json_key['private_key'], 'utf-8'), scope=scope)
gc = gspread.authorize(credentials)
我的下一步是尝试打开谷歌电子表格。我创建了我的谷歌驱动器的主文件夹名为“迈克”电子表格,但试图通过访问它:
gc.open_by_url("https://docs.google.com/spreadsheets/d/1HH7BKsnB2Rd5rlAr7S2H3avUtO4GkqeWrXJfYKKooNA/edit#gid=0")
gc.open("Mike")
gc.open_by_key("1HH7BKsnB2Rd5rlAr7S2H3avUtO4GkqeWrXJfYKKooNA")
所有这三个返回相同的错误:
gspread.exceptions.SpreadsheetNotFound
我认为api访问可能通过项目链接到另一个云存储,而不是我个人的谷歌驱动器,这就是为什么它不访问它。能否有更多经验的人请指点我正确的方向,看看我做错了什么。所有的帮助表示赞赏。谢谢。
您的意思是您必须与该帐户共享电子表格? –