有没有办法指定 "client_secret.json" 的确切路径

Is there a way to specify exact path to "client_secret.json"

我是新手,我真的不知道现在该怎么办,我需要能够输入 "client_secret.json" 文件的确切路径,但在每个教程中我都看到它只使用文件名在同一目录中,但我的不在。

creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)

是的,任何接受文件名的地方都将接受绝对或相对路径。你在谈论相对路径(在同一个目录中),你可以像这样使用它们:

creds = ServiceAccountCredentials.from_json_keyfile_name('../client_secret.json', scope)

其中 ../ 指定上一级文件夹,然后查找您的文件。此外,您可以使用绝对路径,例如:

creds = ServiceAccountCredentials.from_json_keyfile_name('C:\Users\myUser\Desktop\client_secret.json', scope)

不过通常建议使用相对路径,因为这样可以将整个项目文件夹移动到另一个 place/drive 而不会破坏所有链接。

相对路径也可以像这样在树中上下导航:

creds = ServiceAccountCredentials.from_json_keyfile_name('../../../SomeFolder/SubFolder/client_secret.json', scope)