[英]Getting "Requested entity was not found" when fetching Google Sheets data Using REST API v4
So, I am trying to fetch data from my Google Sheets using REST API v4.因此,我正在尝试使用 REST API v4 从我的 Google 表格中获取数据。 The URL for the spreadsheet is
电子表格的 URL 是
https://docs.google.com/spreadsheets/d/1OaknELJVzHxsz5UkH4asuC_xIjgVF3s7JldrxiVuRc/edit#gid=2107620388
So, my spreadsheetId
is 1OaknELJVzHxsz5UkH4asuC_xIjgVF3s7JldrxiVuRc
.所以,我的
spreadsheetId
1OaknELJVzHxsz5UkH4asuC_xIjgVF3s7JldrxiVuRc
是1OaknELJVzHxsz5UkH4asuC_xIjgVF3s7JldrxiVuRc
。 I am following this link to fetch the data.我正在关注此链接以获取数据。 The
API
to use, as per the document is根据
API
要使用的API
是
GET https://sheets.googleapis.com/v4/spreadsheets/spreadsheetId/values/Sheet1!A1:D5
Now, for the sheet
, I have 2 sheets - transactions
and categories
.现在,对于工作
sheet
,我有 2 张工作表 - transactions
和categories
。
So, my final URL
to use became所以,我要使用的最终
URL
变成了
https://sheets.googleapis.com/v4/spreadsheets/1OaknELJVzHxsz5UkH4asuEC_xIjgVF3s7JldrxiVuRc/values/transactions
I used the following curl
call to fetch the data我使用以下
curl
调用来获取数据
curl -v \
-H 'Authorization: Bearer ya29.GlxSB5uTisAfJ3umjYbGGdHBWeeuoBpQtytjdHc2QfP2lwVWqsQ7RwT-Or0z7VRAVQzilVWkweZ2WcH3TQqVnmoCZDe3rTn3euZ4MsoV1mCUpNh2bV-KHEhD16Q' \
-H 'Content-Type: application/json' \
https://sheets.googleapis.com/v4/spreadsheets/1OaknELJVzHxsz5UkH4asuEC_xIjgVF3s7JldrxiVuRc/values/transactions
But, I get the error as below但是,我收到如下错误
* Trying 2607:f8b0:400a:804::200a...
* TCP_NODELAY set
* Connected to sheets.googleapis.com (2607:f8b0:400a:804::200a) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-ECDSA-CHACHA20-POLY1305
* ALPN, server accepted to use h2
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google LLC; CN=*.googleapis.com
* start date: Jul 2 19:21:00 2019 GMT
* expire date: Sep 24 18:57:00 2019 GMT
* subjectAltName: host "sheets.googleapis.com" matched cert's "*.googleapis.com"
* issuer: C=US; O=Google Trust Services; CN=Google Internet Authority G3
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fe5d7800000)
> GET /v4/spreadsheets/1OaknELJVzHxsUkH4asuEC_xIjgVF3s7JldrxiVuRc/values/transactions HTTP/2
> Host: sheets.googleapis.com
> User-Agent: curl/7.54.0
> Accept: */*
> Authorization: Bearer ya29.GlxSB5uTisAfJ3umjYbGGdHBWeeutytjdHc2QfP2lwVWqsQ7RwT-Or0z7VRAVQzilVWkweZ2WcH3TQqVnmoCZAehDe3rTn3euZ4MsoV1mCUpNh2bV-KHEhD16Q
> Content-Type: application/json
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
< HTTP/2 404
< vary: X-Origin
< vary: Referer
< vary: Origin,Accept-Encoding
< content-type: application/json; charset=UTF-8
< date: Fri, 26 Jul 2019 23:34:05 GMT
< server: ESF
< cache-control: private
< x-xss-protection: 0
< x-frame-options: SAMEORIGIN
< alt-svc: quic=":443"; ma=2592000; v="46,43,39"
< accept-ranges: none
<
{
"error": {
"code": 404,
"message": "Requested entity was not found.",
"status": "NOT_FOUND"
}
}
* Connection #0 to host sheets.googleapis.com left intact
I tried other A1 Notation
, but none of them worked我尝试了其他
A1 Notation
,但都没有奏效
transactions!A:B
transactions!A1:B2
categories!A:B
transactions
categories
I know that my Bearer
token is valid and in scope because I am able to create a spreadsheet
.我知道我的不
Bearer
令牌有效且在范围内,因为我能够创建spreadsheet
。 Also, I am using the following scope for my app此外,我正在为我的应用程序使用以下范围
https://www.googleapis.com/auth/drive.file
What am I doing wrong here?我在这里做错了什么? Thanks
谢谢
If my understanding is correct, how about this answer?如果我的理解是正确的,这个答案怎么样?
When the error message of Requested entity was not found.
当
Requested entity was not found.
的错误消息时Requested entity was not found.
occurs, the following reasons can be considered.出现这种情况,可以考虑以下原因。
Unable to parse range: ###
is shown.Unable to parse range: ###
的错误消息Unable to parse range: ###
。https://www.googleapis.com/auth/drive.file
, the files by created with the access token including this scope can be accessed.https://www.googleapis.com/auth/drive.file
范围的情况下,可以访问使用包含此范围的访问令牌创建的文件。 You might try to access to the Spreadsheet which is not created with the the access token including the scope. From your question, when the Spreadsheet ID is correct, it is considered that the latter is the reason of your issue.从您的问题来看,当电子表格ID正确时,则认为后者是您问题的原因。
In order to avoid this, I would like to propose the following 2 patterns.为了避免这种情况,我想提出以下两种模式。 Please think of this answer as just one of several answers.
请将此答案视为几个答案之一。
When you are required to use the scope of https://www.googleapis.com/auth/drive.file
, how about this?当你需要使用
https://www.googleapis.com/auth/drive.file
的范围时,这个怎么样?
By the method of spreadsheets.create, create new Spreadsheet using the access token including the scope of https://www.googleapis.com/auth/drive.file
.通过spreadsheets.create的方法,使用包括
https://www.googleapis.com/auth/drive.file
范围的访问令牌创建新的电子表格。 ANd set some values to the created Spreadsheet.并为创建的电子表格设置一些值。 This can be done by manual operation.
这可以通过手动操作来完成。 And please retrieve the Spreadsheet ID.
并请检索电子表格 ID。
curl \\ -H 'Authorization: Bearer ###' \\ -H 'Content-Type: application/json' \\ -d '{"properties": {"title": "sample"}}' \\ https://sheets.googleapis.com/v4/spreadsheets
Retrieve the values from the created Spreadsheet using the method of spreadsheets.values.get of Sheets API.使用Sheets API 中的spreadsheets.values.get 方法从创建的Spreadsheet 中检索值。
curl \\ -H 'Authorization: Bearer ###' \\ https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/transactions
https://www.googleapis.com/auth/drive.file
as follows. https://www.googleapis.com/auth/drive.file
的作用域做了如下说明。View and manage Google Drive files and folders that you have opened or created with this app
查看和管理您使用此应用打开或创建的 Google Drive 文件和文件夹
When you can use other scope instead of https://www.googleapis.com/auth/drive.file
, how about using the scope of https://www.googleapis.com/auth/spreadsheets.readonly
?当您可以使用其他范围而不是
https://www.googleapis.com/auth/drive.file
,如何使用https://www.googleapis.com/auth/spreadsheets.readonly
的范围? In this case, you can retrieve the values from the existing Spreadsheet that you have the error of Requested entity was not found.
在这种情况下,您可以从现有的电子表格中检索您有错误的
Requested entity was not found.
. .
curl \
-H 'Authorization: Bearer ###' \
https://sheets.googleapis.com/v4/spreadsheets/{spreadsheetId}/values/transactions
https://www.googleapis.com/auth/spreadsheets
.https://www.googleapis.com/auth/spreadsheets
。 as the scope. If I misunderstood your question and this was not the direction you want, I apologize.如果我误解了您的问题并且这不是您想要的方向,我深表歉意。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.