简体   繁体   English

谷歌表格入门问题 API

[英]Issues getting started with google sheets API

I am trying to use python gsheets library to download a google sheets document as a csv file using the following tutorial: ( https://pypi.org/project/gsheets/ )我正在尝试使用 python gsheets库使用以下教程将 google 表格文档下载为csv文件:( https://pypi.org/project/gsheets/ )

I have done all of the following:我已完成以下所有操作:

  • pip install gsheets
  • Logged into Google Developer Console and created New credentials > OAuth client ID登录 Google Developer Console 并创建新凭据> OAuth 客户端 ID
  • Downloaded the json file of the client ID I created and saved it into my users folder as: client_secrets.json下载我创建的客户端 ID 的json文件并将其保存到我的用户文件夹中: client_secrets.json

According to the example project I'm following another file, named storage.json in this example, will be created after successful authorization to cache OAuth data.根据示例项目,我正在关注另一个文件,在本示例中名为 storage.json,将在成功授权后创建以缓存 OAuth 数据。

I then try creating a Sheets object:然后我尝试创建一个表格 object:

>>> from gsheets import Sheets

>>> sheets = Sheets.from_files('~/client_secrets.json', '~/storage.json')

But when I do this I get the following error: FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/client_secrets.json'但是当我这样做时,出现以下错误: FileNotFoundError: [Errno 2] No such file or directory: 'C:/Users/client_secrets.json'

I know that the client_secrets.json is in my user directory and properly spelled, why else would I be getting this error?我知道client_secrets.json在我的用户目录中并且拼写正确,否则为什么会出现此错误?

I am guessing you are using windows, meaning the Users is not your actual directory, it is actually C:/Users/username/我猜你正在使用 windows,这意味着用户不是你的实际目录,它实际上是C:/Users/username/

You could have Documents and Desktop and Downloads folders in there.您可以在其中包含文档、桌面和下载文件夹。

Try this instead of using the tilde.试试这个而不是使用代字号。

from gsheets import Sheets

sheets = Sheets.from_files(r'C:\Users\username\client_secrets.json', r'C:\Users\username\storage.json')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM