【发布时间】:2019-07-26 06:22:18
【问题描述】:
我已经能够获得 access_token 并且我还能够拨打 Google Drive 的 API 电话。
curl -v -H 'Authorization: Bearer ya29.GltQBdS3y-QkCbKhO5K5pO19bBPaHh-KXZJw2ftw2tyxqSXEAYo06FQfHPSQmFtuN7XAlzb9k7cQw2ZkyBsKDcpX91_N3LObEw_Zgj8OvpMwCCPNK1UDjT' -H 'Content-Type: application/json' -d '{"uploadType": "simple", "title": "mb", "mimeType": "application/vnd.google-apps.folder"}' https://www.googleapis.com/upload/drive/v3/files
但是,在 Google Drive 上创建的是一个以我的请求正文作为文件内容的文件
使用curl 的整个有效载荷如下所示
* Trying 2607:f8b0:400a:800::200a...
* TCP_NODELAY set
* Connected to www.googleapis.com (2607:f8b0:400a:800::200a) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* successfully set certificate verify locations:
* CAfile: /etc/ssl/cert.pem
CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Client hello (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-ECDSA-CHACHA20-POLY1305
* ALPN, server accepted to use h2
* Server certificate:
* subject: C=US; ST=California; L=Mountain View; O=Google LLC; CN=*.googleapis.com
* start date: Jun 18 08:35:41 2019 GMT
* expire date: Sep 10 08:16:00 2019 GMT
* subjectAltName: host "www.googleapis.com" matched cert's "*.googleapis.com"
* issuer: C=US; O=Google Trust Services; CN=Google Internet Authority G3
* SSL certificate verify ok.
* Using HTTP2, server supports multi-use
* Connection state changed (HTTP/2 confirmed)
* Copying HTTP/2 data in stream buffer to connection buffer after upgrade: len=0
* Using Stream ID: 1 (easy handle 0x7fcc1c006600)
> POST /upload/drive/v3/files HTTP/2
> Host: www.googleapis.com
> User-Agent: curl/7.54.0
> Accept: */*
> Authorization: Bearer ya29.GltQBzZdS3y-QkCbO5K5pO19bBPaHh-KXZJw2ftw2tyxqSXEAYo06FQ6QmFtuN7XAlzb9k7cQw2ZkUZkyBscpX91_N3LObEw_Zgj8OvpMwCCPNK1UDjT
> Content-Type: application/json
> Content-Length: 89
>
* Connection state changed (MAX_CONCURRENT_STREAMS updated)!
* We are completely uploaded and fine
< HTTP/2 200
< x-guploader-uploadid: AEnB2UpR0hclmVI75f-2hK49hCe3OpA3dkW7GR5PCgd4DgOOkeL2KSoVQDgC-bThMDzXvqcYTaWU3St1pruugvcpst9yaslA
< 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: Thu, 25 Jul 2019 15:23:02 GMT
< content-length: 124
< server: UploadServer
< alt-svc: quic=":443"; ma=2592000; v="46,43,39"
<
{
"kind": "drive#file",
"id": "1MZ4s2ikDqTU5tu-5LDuyMx84TwHgw7",
"name": "Untitled",
"mimeType": "application/json"
}
* Connection #0 to host www.googleapis.com left intact
我做错了什么?
谢谢
【问题讨论】:
标签: javascript rest curl google-drive-api