Oauth2 Google Drive脱机访问不适用于非谷歌应用程序文件? [英] Oauth2 Google Drive offline access not working for non-google app files?

查看:144
本文介绍了Oauth2 Google Drive脱机访问不适用于非谷歌应用程序文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Google Drive API中遇到了令人沮丧的问题。



这是Google App Engine Java环境。

我需要根据脱机权限下载文件 - 文件与提供脱机权限的用户共享(可以编辑)。我正在申请完整的 https://www.googleapis.com/auth/drive 范围。我存储了生成的刷新标记。



然后,应用程序使用此刷新标记获取访问令牌,它用来尝试下载文件。如果文件是Google Apps文件(Google文档,电子表格等),则为工作文件,但如果文件是包含内容的上传文件(例如PDF文件,Word文件等)则为401。我可以通过在共享URL附加一个简单的级别来确认这一点:access_token = xxxx - 这适用于Google Apps文件,但不适用于上传的普通文件,即webcontentlink网址上的401。请注意, https://www.googleapis.com/drive/v2/files/端点使用随后在下载呼叫中失败的访问令牌正确响应上传文件的元数据。

来自直接url调用(包含access_token =)或servlet调用的完整html响应是

 < HTML> 
< HEAD>
< TITLE>未经授权的< / title>
< / HEAD>
< BODY BGCOLOR =#FFFFFFTEXT =#000000>
< H1>未经授权< / H1>
< H2>错误401< / H2>
< / BODY>
< / HTML>

在驱动器中的非本机文件上有离线Google身份验证的已知问题吗?

解决方案

根据文件属性的描述,您应该使用downloadUrl属性而不是webContentLink。


$ b downloadUrl - 文件的短期下载URL。这仅适用于内容存储在Drive中的文件。



webContentLink - 用于在浏览器中下载文件内容的链接使用基于Cookie的身份验证 STRONG>。在内容公开分享的情况下,内容可以在没有任何凭证的情况下下载。


Having a very frustrating issue with Google Drive API.

This is a Google App Engine Java environment.

I need to download a file based on an offline permission - the file is shared ("Can Edit") with the user who gives the offline permission. I am requesting full https://www.googleapis.com/auth/drive scope. I store off the refresh token this generates.

The app then uses this refresh token to get an access token, which it uses to try and download a file. This works file if the file is a Google Apps file (a Google document, spreadsheet etc.) but gives a 401 if the file is an uploaded file with content (e.g. a PDF file, Word file etc.). I can confirm this at a simple level by appending the share urls with ?access_token=xxxx - this works for the Google Apps file but not for an uploaded normal file, which 401's on the webcontentlink url. Note that the https://www.googleapis.com/drive/v2/files/ endpoint responds correctly with the metadata for the uploaded file using the access token that subsequently fails on the download call.

The full html response from either a direct url call (with access_token=) or a servlet call is

<HTML>
<HEAD>
<TITLE>Unauthorized</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000">
<H1>Unauthorized</H1>
<H2>Error 401</H2>
</BODY>
</HTML>

Is there a known issue with offline Google auth on non native files in Drive?

解决方案

Based on the descriptions of file attributes, you should probably be using the downloadUrl attribute rather than webContentLink.

downloadUrl - Short lived download URL for the file. This is only populated for files with content stored in Drive.

webContentLink - A link for downloading the content of the file in a browser using cookie based authentication. In cases where the content is shared publicly, the content can be downloaded without any credentials.

这篇关于Oauth2 Google Drive脱机访问不适用于非谷歌应用程序文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆