尝试下载文件时,Google Drive API返回403 - 没有提供有关错误的信息

时间:2014-08-19 12:23:28

标签: ruby-on-rails ruby google-drive-realtime-api google-drive-api

所以,我有一个ruby on rails项目,我正在使用google-api gem并且我试图从我之前授予我的项目访问和管理权限的帐户下载文件我的谷歌驱动器文件。我有刷新令牌和访问令牌,一段时间,下载工作正常。出于某种原因,在access_token到期之后,即使我使用刷新(它确实有效)从API请求一个新的,下载请求返回403错误,没有任何关于403错误的信息。

首先:为什么在刷新access_token后,我仍然收到403错误? 第二:为什么回复没有返回有关错误的任何信息?

Fyi,如果我转到我的帐户,取消授权该应用程序,然后通过我的应用程序再次授权,下载工作再次正常。

我真的需要帮助,因为如果它不起作用,这会破坏我的整个项目。

编辑:再次尝试查看问题是否仍在发生。我昨天删除了我的帐户,再次授予管理文件权限,直到access_token过期。之后,即使在使用刷新令牌更新访问权限之后,它也会给出403错误消息。以下是我从client.execute获取的内容(使用客户端密钥和密码编辑):

  

来自Google API的回复:#" 16653014193614665626"," e" =>"下载"," gd" =>& #34; true"},@ header = {" User-Agent" =>" google-api-ruby-client / 0.7.1 Linux / 3.13.0-24-generic \ n(gzip)","接受编码" =>" gzip","内容类型" =>"& #34;},@ api_method = nil,@ authenticated = nil,@ authorization =#https://accounts.google.com/o/oauth2/auth>,@ token_credential_uri =#https://accounts.google.com/ o / oauth2 / token>,@ expiry = 60,@ extension_parameters = {},@ additional_parameters = {},@ client_id =" ***。apps.googleusercontent.com",@ client_secret =&#34 ; ***",@ scope = [" https://www.googleapis.com/auth/drive"," https://www.googleapis.com/auth/userinfo.email"],@ access_token =" * **",@ refresh_token =" ***">,@ body ="",@ http_method =:get,@ uri =#>,@ response =#@ request = #request_headers = {" User-Agent" =>" google-api-ruby-client / 0.7.1 Linux / 3.13.0-24-generic \ n (gzip)","接受编码" =>" gzip"," Content-T ype" =>"","授权" =>"承载 * ","缓存-Control" =>" no-store"} @ ssl =#@ response_headers = {" access-control-allow-origin" =>" *& #34;," access-control-allow-credentials" =>" false"," access-control-allow-headers" =>&#34 ;接受,接受语言,授权,缓存控制,内容处理,内容编码,内容语言,内容长度,内容-MD5,内容范围,内容类型,日期,GData版本,主机,如果-Match,If-Modified-Since,If-None-Match,If-Unmodified-Since,Origin,OriginToken,Pragma,Range,Slug,Transfer-Encoding,X-ClientDetails,X-GData-Client,X-GData-Key ,X-Goog-AuthUser,X-Goog-PageId,X-Goog-Encode-Response-If-Executable,X-Goog-Correlation-Id,X-Goog-Request-Info,X-Goog-Experiments,x-goog -iam-role,x-goog-iam-authorization-token,X-Goog-Spatula,X-Goog-Upload-Command,X-Goog-Upload-Content-Disposition,X-Goog-Upload-Content-Length,X -Goog上传内容-Type,X-Goog-Upload-File-Name,X-Goog-Upload-Offset,X-Goog-Upload-Protocol,X-Goog-Visitor-Id,X-HTTP-Method-Override,X-JavaScript-User -Agent,X-Pan-Versionid,X-Origin,X-Referer,X-Upload-Content-Length,X-Upload-Content-Type,X-Use-HTTP-Status-Code-Override,X-YouTube-VVT ,X-YouTube-Page-CL,X-YouTube-Page-Timestamp"," access-control-allow-methods" =>" GET,OPTIONS",&# 34; date" =>" Wed,20 Aug 2014 13:13:22 GMT"," expires" =>" Wed,2014年8月20日13: 13:22 GMT","缓存控制" =>"私人,max-age = 0","服务器" =>&#34 ; UploadServer(\"建于2014年8月12日13:30:28(1407875428)\")"," content-length" =>" 0& #34;," content-type" =>" text / html; charset = UTF-8"," alternate-protocol" =>" 443:quic"," connection" =>" close&# 34;} @ status = 403>>>

在寻找要隐藏的东西(比如access_token)时分析响应后,是否有可能是" access-control-allow-methods"具有日期和到期日期的参数在这里是相同的问题吗?

2 个答案:

答案 0 :(得分:3)

似乎downloadUrl直接连接到访问令牌。通过存储downloadUrl,第一次访问文件的元数据并使用相同的downloadUrl和新的访问令牌,API返回403错误。通过每次请求新令牌时请求新的downloadUrl,它都可以正常工作。

答案 1 :(得分:0)

403错误意味着您没有所需的权限,在这种情况下,您尝试使用过期的令牌,这听起来像您的Cookie政策有问题,将您的Cookie政策更改为无,并让我们知道问题是否会消失。

快乐编码