gpt4 book ai didi

javascript - Google Drive API 使用 curl 调用创建文件而不是文件夹

转载 作者:行者123 更新时间:2023-11-30 19:23:22 25 4
gpt4 key购买 nike

我已经能够获得 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 上创建的是一个以我的请求正文作为文件内容的文件 enter image description here
enter image description here

使用 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

我做错了什么?

谢谢

最佳答案

  • 您想使用 curl 命令在您的 Google 云端硬盘中创建新文件夹。
  • 您已经能够使用 Drive API。
    • 您的访问 token 可用于 POST 方法。

如果我的理解是正确的,这个修改怎么样?

修改点:

  • 创建新文件夹时,您可以使用 https://www.googleapis.com/drive/v3/files 作为端点。
  • 当使用 Drive API v3 时,可以通过 name 属性设置文件夹名称。

当上述修改反射(reflect)到你的curl命令时,它变成如下。

修改后的curl命令:

curl \
-H 'Authorization: Bearer ### your access token ###' \
-H 'Content-Type: application/json' \
-d '{"name": "mb", "mimeType": "application/vnd.google-apps.folder"}' \
https://www.googleapis.com/drive/v3/files

引用:

如果我误解了您的问题并且这不是您想要的结果,我深表歉意。

关于javascript - Google Drive API 使用 curl 调用创建文件而不是文件夹,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57205546/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com