我对Google Drive API有一些非常奇怪的问题。
在这里跟我说,有很多东西要解释。
我最初使用我的一个Google帐户运行API - 为简单起见,我们称之为test@google.com 。 我让Google Picker用户界面正常工作,它正确显示了我的云端硬盘帐户中的文件列表。
我将它设置为我的APP_ID,我有一些服务器端逻辑,使用官方google-ruby-api-client gem连接到Drive API,使用drive.files.get端点。 然后,我可以使用此代码段下载文件的元数据:
require 'google/api_client' client = Google::APIClient.new # client ID and secret from Google APIs Console client.authorization.client_id = "{CLIENT_ID}" client.authorization.client_secret = "{SECRET}" client.authorization.redirect_uri = "http://myapp.com/users/auth/gdrive" # access token stored in database from oauth2 flow client.authorization.access_token = "TOKEN" client.authorization.scope = [ "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile" ] result = client.execute!( :api_method => 'drive.files.get', :version => 'v2', :parameters => { 'fileId' => params[:file_id] })使用test@google.com帐户我尝试了这个,结果返回文件的元数据,我可以下载文件。 所有的桃子。
当我使用其他 Google帐户时会出现问题。 我可以访问Picker中的文件,但是当使用上面的fileId使用fileId将请求发送到服务器时,我只是不断收到404错误,说该文件不存在。 我还尝试使用谷歌提供的OAuth 2.0 Playground访问文件的元数据,但奇怪的是我仍然遇到了这个错误,但是当我使用test@google.com帐户时,我也遇到了同样的404错误。
我唯一能想到的是,我提交了一个包含所有Google云端硬盘详细信息的应用版本,并通过Chrome网上应用店安装了该应用。 在我意识到它作为支持驱动器的应用程序出现在每个人之后,我立即将其删除并将manifest.json文件更改回其正常的非驱动器启用状态。 我确实读到你应该通过Chrome网上商店安装应用程序才能正常工作,但我也读到了不再是这种情况了。 您安装的Chrome网上应用店应用是否存储在Google的云端,以便他们知道是为特定帐户安装的? 或者是本地安装的网上商店应用程序? 我很困惑。
我在这里想念的是什么? 我很久没有对API感到沮丧了。 请帮忙!
I'm having some seriously weird issues with the Google Drive API.
Bear with me here, there's a lot to explain.
I originally got the API working using one of my Google accounts -- let's call it test@google.com for simplicity. I got the Google Picker UI working and it correctly displays the list of files in my Drive account.
I set it to my APP_ID and I have some server-side logic that uses the official google-ruby-api-client gem to connect to the Drive API using the drive.files.get endpoint. I can then download the file's metadata using this snippet:
require 'google/api_client' client = Google::APIClient.new # client ID and secret from Google APIs Console client.authorization.client_id = "{CLIENT_ID}" client.authorization.client_secret = "{SECRET}" client.authorization.redirect_uri = "http://myapp.com/users/auth/gdrive" # access token stored in database from oauth2 flow client.authorization.access_token = "TOKEN" client.authorization.scope = [ "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/userinfo.email", "https://www.googleapis.com/auth/userinfo.profile" ] result = client.execute!( :api_method => 'drive.files.get', :version => 'v2', :parameters => { 'fileId' => params[:file_id] })With the test@google.com account I tried this on, the result comes back with the file's metadata, and I'm able to download the file. All peachy.
The problem comes when I use a different Google account. I can access the files in Picker, but when the request is sent to the server with the fileId using the above, I just keep getting a 404 error, saying that the file doesn't exist. I've also tried to access the file's metadata using the OAuth 2.0 Playground provided by google, but the weird thing is that I still get that error, but I also get the same 404 error when I use the test@google.com account.
The only thing I can really think of is that I submitted a version of my app with all the Google Drive details once, and installed the app via the Chrome Webstore. After I realized it was showing up for everyone as a Drive-enabled app, I promptly removed it and changed the manifest.json file back to its normal, non-Drive enabled state. I did read that you should have the app installed via the Chrome Webstore to work properly, but I also read that that's not the case anymore. Are your installed Chrome Webstore apps stored in Google's cloud somewhere so they know that it was installed for a particular account? Or are webstore apps just installed locally? I'm so confused.
What am I missing here? I haven't been this frustrated with an API in a really long time. Please help!
最满意答案
感谢Ali Afshar的答案 - 解决方案(目前)暂时使用Google Drive的全部范围而不仅仅是drive.file范围。
例如,而不是使用此范围,
https://www.googleapis.com/auth/drive.file改用这个:
https://www.googleapis.com/auth/driveThanks to Ali Afshar for the answer -- the solution (for now) is to temporarily use the full scope of Google Drive instead of just the drive.file scope.
e.g. instead of using this scope,
https://www.googleapis.com/auth/drive.fileuse this one instead:
https://www.googleapis.com/auth/drive更多推荐
发布评论