如何将不同用户的 Google Drive API files.list 请求放在同一批请求中?

StackOverflow https://stackoverflow.com//questions/25023613

  •  21-12-2019
  •  | 
  •  

通常情况下,人们会使用 BatchHttpRequest 聚合多个请求,但是如果我想列出两个不同用户的文件怎么办?

名义上,每个用户需要一个 oauth2 令牌。 BatchHttpRequest 要么需要一个 http 批处理的对象(处理凭据),或者将其从遇到的第一个批处理请求中提取出来 .execute() 叫做。

使用 oauth1 对每个批量请求进行签名会产生正确的结果(每个用户有不同的提要)。但是,使用 oauth2 并手动构建有效负载会产生相同的提要(与第一个批处理请求中的用户匹配):

POST /batch HTTP/1.1
Host: www.googleapis.com
Content-Type: multipart/mixed; boundary=blah
Content-Length: 572
accept-encoding: gzip, deflate
Cache-Control: no-cache

--blah
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: <b29c5de2-0db4-490b-b421-6a51b598bd22+1>

GET /drive/v2/changes HTTP/1.1
Authorization: Bearer ya29.UQAabvlG2hnRPyEAAADUm7vkDe_qg7L49R655IyxvgBnkN7_PEgE3IG7UnZ_ZEmJwUK_6fSV4kTHjNQIjTk
accept: application/json
--blah
Content-Type: application/http
Content-Transfer-Encoding: binary
Content-ID: <b29c5de2-0db4-490b-b421-6a51b598bd22+2>

GET /drive/v2/changes HTTP/1.1
Authorization: Bearer ya29.UQBu8f9W8S5E6RwAAAAPqCOiqoFW3QEFYkBvQGx36UVKNHeEhdZT8GPN-P74ng
accept: application/json
--blah

由于 oauth1 有效,似乎这至少在理论上是可能的,尽管我可能会被谷歌错误阻止,其中批次中第一个请求的 oauth2 令牌会覆盖所包含的任何其他授权。

有帮助吗?

解决方案

google提供的客户端不支持这个,但是提供了一个 Authorization 每个请求的标头都将起作用。假设所有授权标头值都正确,给出的示例应该可以工作。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top