2015-12-01 51 views
5

我在嘗試將大量我的Google雲端硬盤文件添加到新的父文件夾。我正在使用批量請求來避免發送太多的請求,但當批處理中添加了多個PATCH請求時,這不起作用。 Google服務器正在返回一個502 Bad Gateway HTTP錯誤響應。什麼是錯的,或者我該如何解決這個問題?爲什麼批處理中有多個PATCH請求時,我的雲端硬盤API請求失敗?

一般:

Remote Address:216.58.196.138:443 
Request URL:https://content.googleapis.com/batch 
Request Method:POST 
Status Code:502 OK 

響應頭:

alt-svc:quic=":443"; ma=604800; v="30,29,28,27,26,25" 
alternate-protocol:443:quic,p=1 
content-length:1613 
content-type:text/html; charset=UTF-8 
date:Tue, 01 Dec 2015 06:18:36 GMT 
server:GFE/2.0 
status:502 

請求頭:

:authority:content.googleapis.com 
:method:POST 
:path:/batch 
:scheme:https 
accept:*/* 
accept-encoding:gzip, deflate 
accept-language:ru,en-US;q=0.8,en;q=0.6,de;q=0.4,pt;q=0.2,uk;q=0.2,it;q=0.2 
authorization:Bearer ya29.PQI-rcaU2_Pd7tq3XufXVWPfje4ioMzBLhvKOieYuFgs2MnxTyQvtJ0QDR7EiWnN5SOPlGo 
content-length:2291 
content-type:multipart/mixed; boundary=batch691088898561756483 
dnt:1 
origin:https://content.googleapis.com 
referer:https://content.googleapis.com/static/proxy.html?jsh=m%3B%2F_%2Fscs%2Fapps-static%2F_%2Fjs%2Fk%3Doz.gapi.en.Dm6zFqHZO9M.O%2Fm%3D__features__%2Fam%3DAQ%2Frt%3Dj%2Fd%3D1%2Ft%3Dzcms%2Frs%3DAGLTcCPQ-9iC9Y-vGIOJ-RoQCZkFL66QXw 
user-agent:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36 
x-chrome-uma-enabled:1 
x-client-data:CKW2yQEIqbbJAQjEtskBCPCIygEI/ZXKAQi8mMoB 
x-clientdetails:appVersion=5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_10_3)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F46.0.2490.86%20Safari%2F537.36&platform=MacIntel&userAgent=Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_10_3)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F46.0.2490.86%20Safari%2F537.36 
x-goog-encode-response-if-executable:base64 
x-javascript-user-agent:google-api-javascript-client/1.1.0-beta 
x-origin:http://app.local 
x-referer:http://app.local 

請求負載:

--batch691088898561756483 
Content-Type: application/http 
Content-Transfer-Encoding: binary 
Content-ID: <0B28tlN6SgYRacHVwdEQ5b1RtZmc> 

PATCH /drive/v2/files/0B28tlN6SgYRacHVwdEQ5b1RtZmc?addParents=0B28tlN6SgYRaS2syM1VGWjllMnc 
X-JavaScript-User-Agent: google-api-javascript-client/0.1 
Authorization: Bearer ya29.PQI-rcaU2_Pd7tq3XufXVWPfje4ioMzBLhvKOieYuFgs2MnxTyQvtJ0QDR7EiWnN5SOPlGo 
X-ClientDetails: appVersion=5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_10_3)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F46.0.2490.86%20Safari%2F537.36&platform=MacIntel&userAgent=Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_10_3)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F46.0.2490.86%20Safari%2F537.36 

--batch691088898561756483 
Content-Type: application/http 
Content-Transfer-Encoding: binary 
Content-ID: <0B28tlN6SgYRadVFRV0lRQW1kVlE> 

PATCH /drive/v2/files/0B28tlN6SgYRadVFRV0lRQW1kVlE?addParents=0B28tlN6SgYRaS2syM1VGWjllMnc 
X-JavaScript-User-Agent: google-api-javascript-client/0.1 
Authorization: Bearer ya29.PQI-rcaU2_Pd7tq3XufXVWPfje4ioMzBLhvKOieYuFgs2MnxTyQvtJ0QDR7EiWnN5SOPlGo 
X-ClientDetails: appVersion=5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_10_3)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F46.0.2490.86%20Safari%2F537.36&platform=MacIntel&userAgent=Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_10_3)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F46.0.2490.86%20Safari%2F537.36 

--batch691088898561756483 
Content-Type: application/http 
Content-Transfer-Encoding: binary 
Content-ID: <0B28tlN6SgYRaLW1qYmxrZUV2S0E> 

PATCH /drive/v2/files/0B28tlN6SgYRaLW1qYmxrZUV2S0E?addParents=0B28tlN6SgYRaS2syM1VGWjllMnc 
X-JavaScript-User-Agent: google-api-javascript-client/0.1 
Authorization: Bearer ya29.PQI-rcaU2_Pd7tq3XufXVWPfje4ioMzBLhvKOieYuFgs2MnxTyQvtJ0QDR7EiWnN5SOPlGo 
X-ClientDetails: appVersion=5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_10_3)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F46.0.2490.86%20Safari%2F537.36&platform=MacIntel&userAgent=Mozilla%2F5.0%20(Macintosh%3B%20Intel%20Mac%20OS%20X%2010_10_3)%20AppleWebKit%2F537.36%20(KHTML%2C%20like%20Gecko)%20Chrome%2F46.0.2490.86%20Safari%2F537.36 

--batch691088898561756483-- 
+0

是的。一次修補一個文件即可。 –

+0

也可以批量運行files.insert工作正常,但files.patch不行。 –

+0

我不修補權限,我修補父母。 –

回答

0

此問題在Google Drive API v3中解決。批次工作正常。

1

嘗試更改URL到https://www.googleapis.com/batch,而不是https://content.googleapis.com/batch

使用您的具體要求和數據,但改變我對每個請求驗證錯誤地接收到200的URL,如預期的舊令牌。

HTTP/1.1 200 OK 
Vary: Origin 
Vary: X-Origin 
Content-Type: multipart/mixed; boundary=batch_NP9EsgqJk5k_AAFjWZ0MHaM 
Date: Thu, 03 Dec 2015 13:52:18 GMT 
Expires: Thu, 03 Dec 2015 13:52:18 GMT 
Cache-Control: private, max-age=0 
X-Content-Type-Options: nosniff 
X-Frame-Options: SAMEORIGIN 
X-XSS-Protection: 1; mode=block 
Server: GSE 
Alternate-Protocol: 443:quic,p=1 
Alt-Svc: quic=":443"; ma=604800; v="30,29,28,27,26,25" 
Content-Length: 2027 

--batch_NP9EsgqJk5k_AAFjWZ0MHaM 
Content-Type: application/http 
Content-ID: <response-0B28tlN6SgYRacHVwdEQ5b1RtZmc> 

HTTP/1.1 401 Unauthorized 
WWW-Authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token 
Content-Type: application/json; charset=UTF-8 
Date: Thu, 03 Dec 2015 13:52:18 GMT 
Expires: Thu, 03 Dec 2015 13:52:18 GMT 
Cache-Control: private, max-age=0 
Content-Length: 249 

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "authError", 
    "message": "Invalid Credentials", 
    "locationType": "header", 
    "location": "Authorization" 
    } 
    ], 
    "code": 401, 
    "message": "Invalid Credentials" 
} 
} 

--batch_NP9EsgqJk5k_AAFjWZ0MHaM 
Content-Type: application/http 
Content-ID: <response-0B28tlN6SgYRadVFRV0lRQW1kVlE> 

HTTP/1.1 401 Unauthorized 
WWW-Authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token 
Content-Type: application/json; charset=UTF-8 
Date: Thu, 03 Dec 2015 13:52:18 GMT 
Expires: Thu, 03 Dec 2015 13:52:18 GMT 
Cache-Control: private, max-age=0 
Content-Length: 249 

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "authError", 
    "message": "Invalid Credentials", 
    "locationType": "header", 
    "location": "Authorization" 
    } 
    ], 
    "code": 401, 
    "message": "Invalid Credentials" 
} 
} 

--batch_NP9EsgqJk5k_AAFjWZ0MHaM 
Content-Type: application/http 
Content-ID: <response-0B28tlN6SgYRaLW1qYmxrZUV2S0E> 

HTTP/1.1 401 Unauthorized 
WWW-Authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token 
Content-Type: application/json; charset=UTF-8 
Date: Thu, 03 Dec 2015 13:52:18 GMT 
Expires: Thu, 03 Dec 2015 13:52:18 GMT 
Cache-Control: private, max-age=0 
Content-Length: 249 

{ 
"error": { 
    "errors": [ 
    { 
    "domain": "global", 
    "reason": "authError", 
    "message": "Invalid Credentials", 
    "locationType": "header", 
    "location": "Authorization" 
    } 
    ], 
    "code": 401, 
    "message": "Invalid Credentials" 
} 
} 

--batch_NP9EsgqJk5k_AAFjWZ0MHaM-- 
+0

即時通訊使用js gapi庫和高級別的包裝,所以我不能改變網址。我創建批處理像這樣gapi.client.newHttpBatch()。 –

0

Google的批處理API文檔記錄很差。這裏有一些想法嘗試:

  1. 您可能使用了錯誤的端點(的https://content.googleapis.com/batch代替https://www.googleapis.com/batch),爲布賴恩已經建議。根據經驗我知道,即使您在每個批處理請求中提供了正確的Host:標頭,您也無法將請求分配到不同的主機名。

  2. 看起來您正在從Chrome瀏覽器提交批量請求,並且它使用SPDY或HTTP/2來提交請求。如果您使用命令行工具(如curl)而不是使用HTTP/1.1發送請求,會發生什麼情況?

  3. 什麼是確切的錯誤響應?看起來您正在通過text/html響應主體獲得502 Bad Gateway響應,這非常奇怪。預期的行爲將爲200 OK響應,其中multipart/mixed響應正文包含針對您提交的每個單獨請求的application/http消息。

  4. 批處理中的PATCH請求都沒有正文,這可能是一個問題。由於您所要做的只是爲每個文件添加一個新的父文件夾,如果您嘗試在批處理中請求POST https://www.googleapis.com/drive/v2/files/{fileId}/parents請求,會發生什麼情況?

如果您正在尋求從谷歌的迴應,你可以嘗試在official Google Apps API issue tracker提交錯誤。但無法保證Google Drive團隊會作出迴應,而且我經常看到有效的和可重複的bug一次仍然未被確認數月。