无需身份验证令牌即可访问Google电子表格API

Nag*_*ran 14 google-authentication google-sheets google-spreadsheet-api google-developers-console

我创建了Google电子表格,并为所有人提供了编辑权限(即使没有登录也可以编辑).

这是链接.我想使用Google Spreadsheet API更新此表.但我收到了错误.我的要求是即使没有访问凭证也通过API更新工作表.

在此输入图像描述

Jür*_*ter 9

可以不用OAuth或写入电子表格API Keys.你需要使用Service Account Keys.

这是我为Node.js环境所做的.

  1. https://console.cloud.google.com/apis/credentials获取服务帐户密钥(您也可以在此处限制此密钥允许使用的内容)
    1. 创建时,请确保单击 Furnish a new private key
    2. 选择JSON何时询问您如何下载密钥.
  2. service account key你刚才生成包括client_email.
    1. 转到谷歌电子表格,并允许它client_email对此文档具有写入权限
  3. 使用以下代码进行身份验证

    let jwtClient = new google.auth.JWT(client_email, null, private_key, [ "https://www.googleapis.com/auth/spreadsheets", ]); //authenticate request jwtClient.authorize(function(err, tokens) { // at this point the authentication is done you can now use `jwtClient` // to read or write to the spreadsheet });

client_email并且private_key是.的一部分service account key

可以在此处找到更详细的描述. http://isd-soft.com/tech_blog/accessing-google-apis-using-service-account-node-js/此外,所有功劳都归功于此页面.


Rey*_*cia 4

您需要获得授权才能提出此类请求

\n\n
\n

您的应用程序发送到 Google Sheets API 的每个请求都需要\n 向 Google 识别您的应用程序。有两种方法可以识别您的应用程序:使用 OAuth 2.0 令牌(它也授权请求)和/或使用应用程序的 API 密钥。下面介绍了如何确定使用哪些选项:

\n\n

如果请求需要授权(例如请求个人的私有数据),则应用程序必须随请求提供 OAuth 2.0 令牌。应用程序还可以提供 API 密钥,但这不是必须的。如果请求不需要授权(例如对公共数据的请求),则应用程序必须提供 API 密钥或 OAuth 2.0 令牌,或者两者都提供,无论选项是什么对您来说最方便。

\n
\n\n

就是这样。没有绕过授权。

\n