Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google api 谷歌API服务账户认证可以';找不到JSON凭据文件_Google Api_Google Oauth_Google Sheets Api - Fatal编程技术网

Google api 谷歌API服务账户认证可以';找不到JSON凭据文件

Google api 谷歌API服务账户认证可以';找不到JSON凭据文件,google-api,google-oauth,google-sheets-api,Google Api,Google Oauth,Google Sheets Api,我无法让Google API找到我的服务帐户凭据。我用正确的名称将必要的JSON文件下载到适当的位置,并直接使用API文档中的Python代码: import gspread gc = gspread.service_account() sh = gc.open("Example spreadsheet (I'll replace this with my actual sheet name later)") print(sh.sheet1.get('A1')) 代码

我无法让Google API找到我的服务帐户凭据。我用正确的名称将必要的JSON文件下载到适当的位置,并直接使用API文档中的Python代码:

import gspread

gc = gspread.service_account()

sh = gc.open("Example spreadsheet (I'll replace this with my actual sheet name later)")

print(sh.sheet1.get('A1'))
代码在
gc=gspread.service\u account()
处停止,出现
FileNotFoundError
。我通过一条错误消息发现,这是因为它查看的文件路径完全错误(我认为它认为我在Mac电脑上,而实际上我在Windows PC上??)。覆盖文件名,即

gc=gspread.service\u帐户(filename=“insert\actual\path\here.json”)

也不起作用,这是神秘的部分。我直接从我的文件资源管理器中复制了该路径,将反斜杠加倍,这样Unicode就不会试图逃避它(发生过一次),尝试了我能想到的对文件路径的所有修改(
%APPDATA%\gspread\service\u account.json
而不是整个过程,等等)-会出什么问题


编辑:@mods,请随意关闭问题!我发现了一个问题,那就是我使用的是Repl.it在线编码环境,而不是本地编码环境。我把所有的东西都转移到空闲状态,它工作得很好。我强烈怀疑Repl.it根本无法访问我的本地文件(我也在Repl.it上尝试过,在不同的地方随机截图,它抛出了相同的错误)。

您也可以在这个线程上尝试答案,以供在使用gspread service_accounts()时参考@Jason我想你链接的第一条线已经过时了?我想我看到了一个不同的线程,它引用了我试图使用的代码的一个旧版本,除非它仍然有效,而且我很傻