使用CURL编辑Google表格文档中的条目 [英] Using CURL to edit entries on google sheets documents

查看:84
本文介绍了使用CURL编辑Google表格文档中的条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

经过一番困惑之后,我确实从公开工作表上阅读了内容:

After some confusion, I did get reading from a public sheet working:

curl https://sheets.googleapis.com/v4/spreadsheets/[sheetID]/values/A1?key=[MyAPIKey]

其中工作表ID来自Google工作表,而[MyAPIKey]来自 https ://developers.google.com/sheets/api/guides/authorizing#APIKey

Where Sheet ID is from google sheets, and [MyAPIKey] is from https://developers.google.com/sheets/api/guides/authorizing#APIKey

它使我可以读取工作表.

It gives me read-access to the sheet.

一旦我尝试写入工作表上的任何单元格(尽管它们是可公开写入的),就会给我一个错误.我可以轻松地从浏览器中匿名编辑它们,而无需任何键,但是,如果没有API密钥,我似乎根本无法编辑它们.

As soon as I try to write to any cells on the sheet (despite them being publicly writable) it gives me an error. I can easily edit them anonymously from my browser without any keys, however, I can't seem to edit them at all without API keys.

如果我发出:

    curl https://sheets.googleapis.com/v4/spreadsheets/[sheetid]/values/Sheet1\!A1?valueInputOption=RAW?key=[MyAPIKey] -X PUT -d "{\"values\":[ [ \"Test\" ] ] }"

我收到: { "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED" } }

I receive: { "error": { "code": 401, "message": "Request is missing required authentication credential. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", "status": "UNAUTHENTICATED" } }

我认为这与由于此任务,我正在避免OAUTH2机制,我不允许应用程序访问整个Google驱动器.如何像通过authkey方法那样通过选择性的基于链接的访问来完成此操作?在OAUTH2中还有其他方法可以一次进行工作表访问吗?

I'm avoiding the OAUTH2 mechanism as for this task, I can't allow applications access to entire google drive. How can this be done with selective link-based access, like is done via the authkey approach? Is there some other way to give sheet-at-a-time access in OAUTH2?

推荐答案

不是,您不能仅使用CURL执行Sheet操作. 错误401 表示您需要访问令牌才能在该工作表上工作.因此,您需要使用OAuth流来消除该错误,并确保定义范围.

Nope, you can't perform Sheet operations using CURL alone. Error 401 means you need access tokens to work on that sheet. So you need to use OAuth flow to get rid of that error and also make sure to define the scope.

表格简介下方有很多快速入门.使用.

There's a bunch of quickstarts below the Introduction to Sheets that you can use.

这篇关于使用CURL编辑Google表格文档中的条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆