无法使用最近的令牌从谷歌驱动器下载文件

时间:2014-06-11 15:59:54

标签: curl google-oauth google-drive-api

将OAuth 2.0用于服务器到服务器应用程序,我创建并签署了JWT。

{"iss":"xxxxx@developer.gserviceaccount.com","scope":"https://www.googleapis.com/auth/drive.file","aud":"https://accounts.google.com/o/oauth2/token","exp":1402499958,"iat":1402496358}

然后,我使用JWT请求令牌,我有“HTTP / 1.1 200 OK”

HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: Fri, 01 Jan 1990 00:00:00 GMT
Date: Wed, 11 Jun 2014 15:02:46 GMT
Content-Disposition: attachment; filename="json.txt"; filename*=UTF-8''json.txt
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alternate-Protocol: 443:quic
Transfer-Encoding: chunked

{
  "access_token" : "ya29.LgCMhuxHD8ivCxsAAAAwrc2qvQsi0B3bG4w-hNmWgstoyEMIsq0JxcfH0qyWIg",
  "token_type" : "Bearer",
  "expires_in" : 3600
}

所以我把令牌放在卷曲请求中

curl -v -k "https://www.googleapis.com/drive/v2/files/0B7_3fthAYmhGNnVGX3owbUtITk0" -H "Authorization: Bearer ya29.LgCMhuxHD8ivCxsAAAAwrc2qvQsi0B3bG4w-hNmWgstoyEMIsq0JxcfH0qyWIg"

且响应未找到404

* About to connect() to www.googleapis.com port 443 (#0)
*   Trying 173.194.67.95... connected
* Connected to www.googleapis.com (173.194.67.95) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
        .......
* SSLv3, TLS handshake, Finished (20):
* SSL connection using RC4-SHA
* Server certificate:
*        subject: C=US, ST=California, L=Mountain View, O=Google Inc, CN=*.googleapis.com
*        start date: 2014-05-22 11:06:31 GMT
*        expire date: 2014-08-20 00:00:00 GMT
*        subjectAltName: www.googleapis.com matched
*        issuer: C=US, O=Google Inc, CN=Google Internet Authority G2
*        SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> GET /drive/v2/files/0B7_3fthAYmhGNnVGX3owbUtITk0 HTTP/1.1
> User-Agent: curl/7.19.5 (amd64-pc-win32) libcurl/7.19.5 OpenSSL/0.9.8k
> Host: www.googleapis.com
> Accept: */*
> Authorization: Bearer ya29.LgCMhuxHD8ivCxsAAAAwrc2qvQsi0B3bG4w-hNmWgstoyEMIsq0JxcfH0qyWIg
>
< HTTP/1.1 404 Not Found
< Content-Type: application/json; charset=UTF-8
< Date: Wed, 11 Jun 2014 15:22:08 GMT
< Expires: Wed, 11 Jun 2014 15:22:08 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
< Transfer-Encoding: chunked
<
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "notFound",
    "message": "File not found: 0B7_3fthAYmhGNnVGX3owbUtITk0"
   }
  ],
  "code": 404,
  "message": "File not found: 0B7_3fthAYmhGNnVGX3owbUtITk0"
 }
}
* Connection #0 to host www.googleapis.com left intact
* Closing connection #0
* SSLv3, TLS alert, Client hello (1):

如果我使用“OAuth 2.0 Playground”中获取的访问令牌,则响应为HTTP / 1.1 200 OK

curl -v -k "https://www.googleapis.com/drive/v2/files/0B7_3fthAYmhGNnVGX3owbUtITk0" -H "Authorization: Bearer ya29.LgCIqvk5z-GKKRoAAACcb2pvdgowNH6otwO7csB955WhiSjixlPo82lDSluduA"

* About to connect() to www.googleapis.com port 443 (#0)
*   Trying 173.194.67.95... connected
* Connected to www.googleapis.com (173.194.67.95) port 443 (#0)
* SSLv3, TLS handshake, Client hello (1):
  .....
* SSL connection using RC4-SHA
* Server certificate:
*        subject: C=US, ST=California, L=Mountain View, O=Google Inc,     CN=*.googleapis.com
*        start date: 2014-05-22 11:06:31 GMT
*        expire date: 2014-08-20 00:00:00 GMT
*        subjectAltName: www.googleapis.com matched
*        issuer: C=US, O=Google Inc, CN=Google Internet Authority G2
*        SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway.
> GET /drive/v2/files/0B7_3fthAYmhGNnVGX3owbUtITk0 HTTP/1.1
> User-Agent: curl/7.19.5 (amd64-pc-win32) libcurl/7.19.5 OpenSSL/0.9.8k
> Host: www.googleapis.com
> Accept: */*
> Authorization: Bearer ya29.LgCIqvk5z-GKKRoAAACcb2pvdgowNH6otwO7csB955WhiSjixlPo82lDSluduA
>
< HTTP/1.1 200 OK
< Expires: Wed, 11 Jun 2014 15:20:52 GMT
< Date: Wed, 11 Jun 2014 15:20:52 GMT
< Cache-Control: private, max-age=0, must-revalidate, no-transform
< ETag: "AkM7BvofPa_Jxo7Kxgh76A7i7OE/MTQwMDUwNTUxNDk4OA"
< Content-Type: application/json; charset=UTF-8
< X-Content-Type-Options: nosniff
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: 1; mode=block
< Content-Length: 2745
< Server: GSE
< Alternate-Protocol: 443:quic
<
{
 "kind": "drive#file",
 "id": "0B7_3fthAYmhGNnVGX3owbUtITk0",
 "etag": "\"AkM7BvofPa_Jxo7Kxgh76A7i7OE/MTQwMDUwNTUxNDk4OA\"",
  .......

我尝试过很多东西,但我不知道问题出在哪里。

0 个答案:

没有答案