Google Drive 批量请求文档需要更新

问题描述 投票:0回答:1

这与文档或批量请求相关 - https://developers.google.com/drive/api/guides/performance#batch-example-request

文档样本:

--END_OF_PART
Content-Length: 337
Content-Type: application/http
content-id: 1
content-transfer-encoding: binary



POST https://www.googleapis.com/drive/v3/files/fileId/permissions?fields=id
Authorization: Bearer authorization_token
Content-Length: 70
Content-Type: application/json; charset=UTF-8



{
  "emailAddress":"[email protected]",
  "role":"writer",
  "type":"user"
}
--END_OF_PART

截至 2 周前(2023 年 7 月的某个时间),我们产品的 Google Drive 批量 API 调用停止工作。它不断出错并出现 HTTP 400(错误请求)失败 - 无法解析 HTTP 标头。

我们最终将其追溯到有效负载中额外的空白行。

这有效:

--END_OF_PART

POST https://www.googleapis.com/drive/v3/files/fileId/permissions?fields=id

--END_OF_PART

这不起作用(2 个空行,如文档中所示)

--END_OF_PART


POST https://www.googleapis.com/drive/v3/files/fileId/permissions?fields=id


--END_OF_PART

请更新文档以反映这一点。我们花了几天时间调试这个问题才发现问题。

此 Curl 请求有效:

--header 'Content-Type: multipart/mixed; boundary=END_OF_PART' \
--header 'Authorization: Bearer <token>' \
--data '--END_OF_PART

GET https://www.googleapis.com/drive/v3/files/<fileid>/permissions

--END_OF_PART--
'```

But this does not:

```curl --location 'https://www.googleapis.com/batch/drive/v3' \
--header 'Content-Type: multipart/mixed; boundary=END_OF_PART' \
--header 'Authorization: Bearer <token>' \
--data '--END_OF_PART


GET https://www.googleapis.com/drive/v3/files/<fileid>/permissions


--END_OF_PART--
'```
google-drive-api
1个回答
0
投票

修改要点:

从您显示的请求正文中,我担心以下修改点。

  • 最后一个边界没有闭合。在这种情况下,使用
    --END_OF_PART--
    代替
    --END_OF_PART
  • 可能需要修改换行符。

当这些要点反映在您的请求正文中时,下面的修改如何?

修改后的请求体:

--END_OF_PART
Content-Type: application/http
Content-ID: 1

POST https://www.googleapis.com/drive/v3/files/fileId/permissions?fields=id
Content-Type: application/json; charset=utf-8"

{"emailAddress":"[email protected]","role":"writer","type":"user"}
--END_OF_PART--

测试:

当我测试以下curl命令时,我确认它工作正常。

curl --location 'https://www.googleapis.com/batch/drive/v3' \
--header 'Content-Type: multipart/mixed; boundary=END_OF_PART' \
--header 'Authorization: Bearer ###' \
--data '--END_OF_PART
Content-Type: application/http
Content-ID: 1

POST https://www.googleapis.com/drive/v3/files/{fileId1}/permissions?fields=id
Content-Type: application/json; charset=utf-8"

{"emailAddress":"###","role":"writer","type":"user"}
--END_OF_PART
Content-Type: application/http
Content-ID: 2

POST https://www.googleapis.com/drive/v3/files/{fileId2}/permissions?fields=id
Content-Type: application/json; charset=utf-8"

{"emailAddress":"###","role":"writer","type":"user"}
--END_OF_PART--'

或者,

curl --location 'https://www.googleapis.com/batch/drive/v3' \
--header 'Content-Type: multipart/mixed; boundary=END_OF_PART' \
--header 'Authorization: Bearer ###' \
--data-binary "@sample.txt"

sample.txt
如下。

--END_OF_PART
Content-Type: application/http
Content-ID: 1

POST https://www.googleapis.com/drive/v3/files/{fileId1}/permissions?fields=id
Content-Type: application/json; charset=utf-8"

{"emailAddress":"###","role":"writer","type":"user"}
--END_OF_PART
Content-Type: application/http
Content-ID: 2

POST https://www.googleapis.com/drive/v3/files/{fileId2}/permissions?fields=id
Content-Type: application/json; charset=utf-8"

{"emailAddress":"###","role":"writer","type":"user"}
--END_OF_PART--

参考:

© www.soinside.com 2019 - 2024. All rights reserved.