这与文档或批量请求相关 - 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--
'```
从您显示的请求正文中,我担心以下修改点。
--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--