Google drive api GDrive可恢复上载响应中缺少位置标头

Google drive api GDrive可恢复上载响应中缺少位置标头,google-drive-api,Google Drive Api,我按照网站上的说明进行可恢复的文件上传 我有一个服务帐户的工作令牌(我验证了我可以列出文件),并且 列出文件的卷曲将确认文件是否存在: $ curl -H "Authorization: Bearer <token>" \ https://www.googleapis.com/drive/v3/files ... { "kind": "drive#file", "id": "0B8f3X4o60bqnWjU5aFIxbHB1bTA", "name": "myObject", "mi

我按照网站上的说明进行可恢复的文件上传

我有一个服务帐户的工作令牌(我验证了我可以列出文件),并且

列出文件的卷曲将确认文件是否存在:

$ curl -H "Authorization: Bearer <token>"  \
https://www.googleapis.com/drive/v3/files
...
{
"kind": "drive#file",
"id": "0B8f3X4o60bqnWjU5aFIxbHB1bTA",
"name": "myObject",
"mimeType": "application/pdf"
},
...
$curl-H“授权:持票人”\
https://www.googleapis.com/drive/v3/files
...
{
“种类”:“驱动器#文件”,
“id”:“0B8f3X4o60bqnWjU5aFIxbHB1bTA”,
“名称”:“myObject”,
“mimeType”:“application/pdf”
},
...

我尝试了wget和Elixir的HTTPotion,结果是一样的。有人知道我做错了什么吗?

尝试使用指南中的以下格式:

示例:启动可恢复上传会话

以下示例显示如何启动可恢复会话以上载新文件:

POST https://www.googleapis.com/drive/v3/files?uploadType=resumable HTTP/1.1
Authorization: Bearer [YOUR_AUTH_TOKEN]
Content-Length: 38
Content-Type: application/json; charset=UTF-8
X-Upload-Content-Type: image/jpeg
X-Upload-Content-Length: 2000000

{
  "name": "myObject"
}
这不是解决方案,因为他/她没有注意到他/她为同一个操作提供了两个不同的URL。然而,看到这两个URL靠得很近,我意识到谷歌的文档是错误的,因为它在文本中使用了以下内容:

 POST https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable
在这个例子中:

 POST https://www.googleapis.com/drive/v3/files?uploadType=resumable
第一个是正确的,第二个是错误的。我希望谷歌的人能阅读并修复文档

我可能会说,对于文件上传和所有其他文件操作,使用不同的URL是糟糕的设计。证据:甚至谷歌在选择示例中使用的一个时也犯了错误

这是我通过
/upload
URL得到的正确响应:

$ curl -i -H "Authorization: Bearer <token>"  \
-H "Content-Type: application/json; charset=UTF-8" \
-H "Content-Length: 50" \
-H "X-Upload-Content-Type: application/pdf" \
-H "X-Upload-Content-Length: 1560010" \
-X POST 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable'  \
-d '{"name": "myObject","mimeType": "application/pdf"}'
HTTP/1.1 200 OK
X-GUploader-UploadID: <upload-id>
Location: https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&upload_id=<upload-id>
Vary: Origin
Vary: X-Origin
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Date: Tue, 01 Aug 2017 06:37:02 GMT
Content-Length: 0
Server: UploadServer
Content-Type: text/html; charset=UTF-8
Alt-Svc: quic=":443"; ma=2592000; v="39,38,37,36,35"
最终一致

 POST https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable
 POST https://www.googleapis.com/drive/v3/files?uploadType=resumable
$ curl -i -H "Authorization: Bearer <token>"  \
-H "Content-Type: application/json; charset=UTF-8" \
-H "Content-Length: 50" \
-H "X-Upload-Content-Type: application/pdf" \
-H "X-Upload-Content-Length: 1560010" \
-X POST 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable'  \
-d '{"name": "myObject","mimeType": "application/pdf"}'
HTTP/1.1 200 OK
X-GUploader-UploadID: <upload-id>
Location: https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&upload_id=<upload-id>
Vary: Origin
Vary: X-Origin
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Date: Tue, 01 Aug 2017 06:37:02 GMT
Content-Length: 0
Server: UploadServer
Content-Type: text/html; charset=UTF-8
Alt-Svc: quic=":443"; ma=2592000; v="39,38,37,36,35"
$ curl -i -H "Authorization: Bearer <token>" \
-H "Content-Type: application/pdf" \
-H "Content-Length: 1560010" \
-X PUT 'https://www.googleapis.com/upload/drive/v3/files?uploadType=resumable&upload_id=<upload-id>' \
--data-binary "@myObject.pdf"
HTTP/1.1 100 Continue

HTTP/1.1 200 OK
X-GUploader-UploadID: <upload-id>
Vary: Origin
Vary: X-Origin
Content-Type: application/json; charset=UTF-8
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Mon, 01 Jan 1990 00:00:00 GMT
Date: Tue, 01 Aug 2017 06:48:47 GMT
Content-Length: 118
Server: UploadServer
Alt-Svc: quic=":443"; ma=2592000; v="39,38,37,36,35"

{
 "kind": "drive#file",
 "id": "<file-id>",
 "name": "myObject",
 "mimeType": "application/pdf"
}
$ curl -H "Authorization: Bearer <token-id>" \
'https://www.googleapis.com/drive/v3/files/<file-id>?alt=media' \
> download.pdf
$ diff download.pdf myObject.pdf
$ echo $status
0
HTTP/1.1 401 Unauthorized
Vary: X-Origin
WWW-Authenticate: Bearer realm="https://accounts.google.com/", error=invalid_token
Content-Type: application/json; charset=UTF-8
Date: Tue, 01 Aug 2017 06:56:35 GMT
Expires: Tue, 01 Aug 2017 06:56:35 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alt-Svc: quic=":443"; ma=2592000; v="39,38,37,36,35"
Accept-Ranges: none
Vary: Origin,Accept-Encoding
Transfer-Encoding: chunked

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