在谷歌文档上下载链接(通过API)到可公开访问的文件返回401

时间:2012-05-08 23:06:52

标签: google-docs-api

我通过文档API上传了一个(pgp)文件,并更改了它 对公众的可见度。但是,我无法公开下载 使用该文件的内容链接。

以下是文件中元数据的xml的相关位 问题

$ curl -H "GData-Version: 3.0" -H "Authorization: Bearer ..." https://docs.google.com/feeds/default/private/full

...
    <content type="application/pgp-encrypted" src="https://doc-0c-c0-docs.googleusercontent.com/docs/securesc/tkl8gnmcm9fhm6fec3160bcgajgf0i18/opa6m1tmj5cufpvrj89bv4dt0q6696a4/1336514400000/04627947781497054983/04627947781497054983/0B_-KWHz80dDXZ2dYdEZ0dGw3akE?h=16653014193614665626&amp;e=download&amp;gd=true"/>
...
    <gd:feedLink rel="http://schemas.google.com/acl/2007#accessControlList" href="https://docs.google.com/feeds/default/private/full/file%3A0B_-KWHz80dDXZ2dYdEZ0dGw3akE/acl"/>

$ curl -H "GData-Version: 3.0" -H "Authorization: Bearer ..." https://docs.google.com/feeds/default/private/full/file%3A0B_-KWHz80dDXZ2dYdEZ0dGw3akE/acl

...
  <entry gd:etag="W/&quot;DUcNRns4eCt7ImA9WhVVFUw.&quot;">
    <id>https://docs.google.com/feeds/id/file%3A0B_-KWHz80dDXZ2dYdEZ0dGw3akE/acl/default</id>
...
    <gAcl:role value="reader"/>
    <gAcl:scope type="default"/>
...

为相关文件返回的角色/范围是reader/default,表示 它是公开的。 (它还会在Web UI中显示公共共享访问权限。)

然而,访问 content元素中的src属性导致:

$ curl --verbose 'https://doc-0c-c0-docs.googleusercontent.com/docs/securesc/tkl8gnmcm9fhm6fec3160bcgajgf0i18/opa6m1tmj5cufpvrj89bv4dt0q6696a4/1336514400000/04627947781497054983/04627947781497054983/0B_-KWHz80dDXZ2dYdEZ0dGw3akE?h=16653014193614665626&e=download&gd=true'

< HTTP/1.1 401 Unauthorized
< Server: HTTP Upload Server Built on May 7 2012 18:16:42 (1336439802)
< WWW-Authenticate: GoogleLogin realm="http://www.google.com/accounts"
< Date: Tue, 08 May 2012 22:48:37 GMT
< Expires: Tue, 08 May 2012 22:48:37 GMT
< Cache-Control: private, max-age=0
< Content-Length: 0
< Content-Type: text/html

2 个答案:

答案 0 :(得分:1)

您似乎正在尝试发布文档:https://developers.google.com/google-apps/documents-list/#publishing_documents_by_publishing_a_single_revision

发布后,rel设置为“http://schemas.google.com/docs/2007#publish”的链接将指向网络上发布的文档。

答案 1 :(得分:0)

我相信这个答案可能有所帮助https://stackoverflow.com/a/11855448/1626594 例如

https://docs.google.com/uc?export=download&id={fileId}

https://docs.google.com/uc?id={fileId}

如果需要,使用查询字符串选项&confirm=no_antivirus不扫描文件。

来源:youtube和上面提到的答案,我没有看到Google提供的任何相关文档。