Google Sheet API v4 [英] Google Sheet API v4

查看:384
本文介绍了Google Sheet API v4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用读取多个范围示例:


https://sheets.googleapis.com/v4/spreadsheets/ {SpreadsheetID} / values:batchGet?ranges = Sheet1!B:B& ranges = Sheet1 !D:D& valueRenderOption = UNFORMATTED_VALUES?majorDimension = COLUMNS


来自: Google Sheets API v4示例
我用我的电子表格ID替换了spreadsheetId。
但是当我发送GET请求(邮递员)时,我收到:

  {
error: {
code:403,
message:请求缺少有效的API密钥。,
status:PERMISSION_DENIED
}
}

比我使用 https://developers.google.com/oauthplayground/
我使用我的电子邮件为Spreadsheet API v4授权,并且最终生成了一个包含密钥的长链接并看到我的数据表的内容正确的响应。

我的问题是:
为什么使用Google API的示例是不可能的( https://developers.google.com/sheets/api/samples/reading )只能替换电子表格ID。
Ps链接到我的电子表格是公开的,我的电子表格是公开的,并且可以使用JSON格式,为了发送带有多个请求的batchGet,Google Spreadsheet API v4的url是否正确使用?

我使用另一种方法,但它的工作原理,但为什么第一种方法(v4)不起作用:

  https://spreadsheets.google.com/feeds/list/ {SpreadsheetID} / od6 / public / values?alt = json 

当我试图在一个请求中合并2个API并收到错误不一致的重复查询参数范围时:



<$ ?p $ p> https://spreadsheets.google.com/feeds/list/ {SpreadsheetID} / OD6 /公共/值:batchGet范围= Sheet 1中B:!B和范围= Sheet 1中d!: D& valueRenderOption = UNFORMATTED_VALUES?majorDimension = COLUMNS

============ ==========================

已编辑:



SpreadSheetID: 1KBk1J7TJCwnayMnTbaysqvFk98kVDdxXWNw2JYc3bW0



可在隐身模式下使用: Spreadsheet



以JSON格式: JSON



参考: Google表格API v4:读取多个范围



与SpreadSheetID相同的例子:错误403

解决方案

网址。这是来自谷歌电子表格api文档。



要获取API密钥: 打开证书页面API控制台。


API密钥:未提供OAuth 2.0令牌的请求必须发送
API密钥。该密钥标识您的项目并提供API访问权限,
配额和报告。



API支持多种类型的API密钥限制。如果您所需的API
密钥尚不存在,请通过单击创建凭证> API密钥在
控制台中创建一个API密钥。您可以通过单击限制键和
选择其中一个限制,在生产中使用它之前限制
键。为了保证您的API密钥安全,
遵循安全使用API​​密钥的最佳实践。



在您拥有API密钥后,您的应用程序可以追加查询$对于所有请求URL,b $ b参数key = yourAPIKey。



API密钥对于嵌入到URL中是安全的;它不需要任何
编码。


Google Spreadsheet Docs


I try to use example "Read multiple ranges":

https://sheets.googleapis.com/v4/spreadsheets/{SpreadsheetID}/values:batchGet?ranges=Sheet1!B:B&ranges=Sheet1!D:D&valueRenderOption=UNFORMATTED_VALUES?majorDimension=COLUMNS

from: Google Sheets API v4 example I replaced "spreadsheetId" with my spreadsheet id. But when I send GET request (by Postman) I receive:

{
  "error": {
    "code": 403,
    "message": "The request is missing a valid API key.",
    "status": "PERMISSION_DENIED"
  }
}

Than I used https://developers.google.com/oauthplayground/ I made authorisation for Spreadsheet API v4 with my email and at the end I generated a long link with key and saw correct response with content of my data table.

My question is next: Why it's imposible to use the example from Google API (https://developers.google.com/sheets/api/samples/reading) only replace the spreadsheet id. P.s Link to my spreadsheet is public, My spreadsheet is public and available in JSON format and what is correct use of url for Google Spreadsheet API v4 in order to send batchGet with multiple requests?

P.s.s I use another approach and it works but why first approach (v4) doesn't work:

https://spreadsheets.google.com/feeds/list/{SpreadsheetID}/od6/public/values?alt=json

When I tried to combine 2 APIs in one request and received and error "Inconsistent repeating query parameter ranges":

https://spreadsheets.google.com/feeds/list/{SpreadsheetID}/od6/public/values:batchGet?ranges=Sheet1!B:B&ranges=Sheet1!D:D&valueRenderOption=UNFORMATTED_VALUES?majorDimension=COLUMNS

======================================
Edited:

SpreadSheetID: 1KBk1J7TJCwnayMnTbaysqvFk98kVDdxXWNw2JYc3bW0

Available in incognito mode: Spreadsheet

In JSON format: JSON

Reference: Google Sheets API v4: Read multiple ranges

The same example with SpreadSheetID: ERROR 403

解决方案

I believe you are missing API in the url. This is from google spreadsheet api doc.

To acquire an API key:

Open the Credentials page in the API Console.

API keys: A request that does not provide an OAuth 2.0 token must send an API key. The key identifies your project and provides API access, quota, and reports.

The API supports several types of restrictions on API keys. If the API key that you need doesn't already exist, then create an API key in the Console by clicking Create credentials > API key. You can restrict the key before using it in production by clicking Restrict key and selecting one of the Restrictions. To keep your API keys secure, follow the best practices for securely using API keys.

After you have an API key, your application can append the query parameter key=yourAPIKey to all request URLs.

The API key is safe for embedding in URLs; it doesn't need any encoding.

Google Spreadsheet Docs

这篇关于Google Sheet API v4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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