寻求Google Batch API的一些帮助, 在同一个域/组织下为两个不同的帐户获得了两个有效的访问令牌,并希望批量打两个电话,每个电话都有自己的授权标题。
如果我正确地阅读了它,应该可以根据the API docs:
外部批处理请求的HTTP标头(内容类型等内容标题除外)适用于批处理中的每个请求。如果在外部请求和单个调用中都指定了给定的HTTP标头,则单个调用标头的值将覆盖外部批处理请求标头的值。单个呼叫的标头仅适用于该呼叫。
例如,如果您为特定呼叫提供授权标头,则该标头仅适用于该呼叫。如果您为外部请求提供Authorization标头,那么该标头将应用于所有单个调用,除非它们使用自己的Authorization标头覆盖它。
使用Postman测试(POST https://www.googleapis.com/batch) 当请求没有身份验证标头但内部请求具有有效的身份验证标头时:
--batch_foobarbaz
Authorization:Bearer <accesstoken1>
Content-Type: application/http Content-ID: one
GET /gmail/v1/users/me/profile
--batch_foobarbaz
Authorization:Bearer <accesstoken2>
Content-Type: application/http
Content-ID: two
GET /gmail/v1/users/me/profile
--batch_foobarbaz--
我得到回复&#34;需要登录&#34;对于这两个请求:
--batch_x-oYQ5TohrI_AAd7PA4mQcg
Content-Type: application/http
Content-ID: response-one
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="https://accounts.google.com/"
Content-Type: application/json; charset=UTF-8
Date: Sun, 12 Nov 2017 12:28:55 GMT
Expires: Sun, 12 Nov 2017 12:28:55 GMT
Cache-Control: private, max-age=0
Content-Length: 238
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
--batch_x-oYQ5TohrI_AAd7PA4mQcg
Content-Type: application/http
Content-ID: response-two
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer realm="https://accounts.google.com/"
Content-Type: application/json; charset=UTF-8
Date: Sun, 12 Nov 2017 12:28:55 GMT
Expires: Sun, 12 Nov 2017 12:28:55 GMT
Cache-Control: private, max-age=0
Content-Length: 238
{
"error": {
"errors": [
{
"domain": "global",
"reason": "required",
"message": "Login Required",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Login Required"
}
}
--batch_x-oYQ5TohrI_AAd7PA4mQcg--
Google指示我,在第二次尝试时,我在请求中添加了一个身份验证标头,其中包含&#34; accesstoken1&#34;希望内部请求标头会覆盖它:
--batch_foobarbaz
Content-Type: application/http
Content-ID: one
Authorization: Bearer <accesstoken1>
GET /gmail/v1/users/me/profile
--batch_foobarbaz
Content-Type: application/http
Content-ID: two
Authorization: Bearer <accesstoken2>
GET /gmail/v1/users/me/profile
--batch_foobarbaz--
然而,内部Authorization标头被忽略,我对两个内部请求都得到相同的响应:
--batch_acwJ2jJl7Vk_AAwDDvF7GqQ
Content-Type: application/http
Content-ID: response-one
HTTP/1.1 200 OK
ETag: "Sa8s0oAMlJSbjHHTmOHVq5KXvZM/ij85zVL5i9x1u7LOtgNBEd-PGZY"
Content-Type: application/json; charset=UTF-8
Date: Sun, 12 Nov 2017 12:52:16 GMT
Expires: Sun, 12 Nov 2017 12:52:16 GMT
Cache-Control: private, max-age=0
Content-Length: 108
{
"emailAddress": "user1@whatever.com",
"messagesTotal": 16,
"threadsTotal": 13,
"historyId": "7294"
}
--batch_acwJ2jJl7Vk_AAwDDvF7GqQ
Content-Type: application/http
Content-ID: response-two
HTTP/1.1 200 OK
ETag: "Sa8s0oAMlJSbjHHTmOHVq5KXvZM/ij85zVL5i9x1u7LOtgNBEd-PGZY"
Content-Type: application/json; charset=UTF-8
Date: Sun, 12 Nov 2017 12:52:16 GMT
Expires: Sun, 12 Nov 2017 12:52:16 GMT
Cache-Control: private, max-age=0
Content-Length: 108
{
"emailAddress": "user1@whatever.com",
"messagesTotal": 16,
"threadsTotal": 13,
"historyId": "7294"
}
--batch_acwJ2jJl7Vk_AAwDDvF7GqQ--
如果有人能理解这一点,我将永远感激
谢谢!
答案 0 :(得分:0)
我猜你的内部身份验证标头会在GET / POST请求之后出现。
例如
获取https://www.googleapis.com/calendar/v3/calendars/primary/events
授权:持票人XXXXXXXXXXXXXXXXXXXX
而不是
授权:承载XXXXXXXXXXXXXXXXXXXX 获得https://www.googleapis.com/calendar/v3/calendars/primary/events。
在您的示例中,它将是
- batch_foobarbaz
Content-Type:application / http
Content-ID:一个
GET / gmail / v1 / users / me / profile
授权:持票人
这对我有用。如果这对您有用,请告诉我。