Google Drive SDK - Java示例不起作用 [英] Google Drive SDK - Java sample not working

查看:126
本文介绍了Google Drive SDK - Java示例不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用官方Java示例来熟悉Google Drive API。但是,在浪费了几个小时后,试图将样本设置为两次后,我仍然无法按预期使用它。



不是显示文件的内容它会在FileServlet(/ svc路径)中引发404错误。更具体地说, service.files()。get(fileId).execute(); 似乎返回null。我已经尝试过使用不同的文件,不同的MIME类型,直接从Google Drive以及使用Google文件选取器。



我已经按照上述步骤尽可能地 https://developers.google.com/drive/examples/java



任何人都可以运行示例吗?



编辑:
当请求URL / svc?file_id = 0B08R9MrOE-ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw 时(404错误在第78行抛出),以下是FileServlet的日志输出:

  2012-04-26 08:21:36.077 
com.google.api.client.http.HttpRequest执行: - ------------请求--------------
GET https://www.googleapis.com/drive/v1/files/0B08R9MrOE- ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw
Accept-Encoding:gzip
User-Agent:Google-HTTP-Java-Client / 1.8.3-beta(gzip)

D 2012-04-26 08:21:36.263
com.google.api.client.http.HttpResponse< init> ;: -------------- RESPONSE ---- ----------
403 OK
content-type:application / json; charset = UTF-8
content-encoding:gzip
日期:星期四
日期:2012年4月26日06:21:36 GMT
过期:星期四
过期:26 Apr 2012 06:21:36 GMT
cache-control:private
cache-control:max-age = 0
x-content-type-options:nosniff
x-frame -options:SAMEORIGIN
x-xss-protection:1; mode = block
content-length:188
server:GSE
x-google-cache-control:remote-fetch
via:HTTP / 1.1 GWA

D 2012-04-26 08:21:36.265
com.google.api.client.http.HttpResponse getContent:响应大小:188字节
D 2012-04-26 08:21:36.271
com.google.api.client.http.HttpResponse getContent:{
error:{
errors:[
{
domain: usageLimits,
reason:dailyLimitExceededUnreg,
message:每日限制已超出,请注册,
extendedHelp:https://code.google。 com / apis / console

],
code:403,
message:每日限制已超过,请注册
}

这听起来很像我不认识你,所以我再次看看我的客户端ID和客户端密钥:我注意到在API控制台中显示了两个客户端ID和客户端密码,一个是Web应用程序的客户端ID,另一个是客户端ID r Drive SDK。我之前使用过一个用于Web应用程序的版本,因此我试图切换到Drive SDK的版本。不幸的是,这并没有改变任何东西。相同的错误...:/ $ / $ / $>

解决方案

我最终设法让它工作。我不确定以前有什么问题,但以下是面对类似问题的提示: Web应用程序的客户端ID和Drive SDK的客户端ID让我感到困惑。不幸的是,文档没有告诉你在哪个地方使用哪一个,但似乎只需要Web应用程序的客户端ID。 如果您更新Chrome扩展程序或API控制台,则可能需要一段时间才能识别这些更改。例如,更改API控制台中的OAuth客户端ID可能需要一段时间才能生效,因为每个人都有缓存。如果您正在测试您的应用程序,那么删除缓存和Cookie有助于加快此过程。 并感谢所有帮助我的人!


I'm trying to get familiar with the Google Drive API using the official Java sample. However, after wasting a few hours and attempting to set the sample up two times, I'm still not able to use it as expected.

Instead of displaying a file's content it throws a 404 error in the FileServlet (/svc path). More specifically, service.files().get(fileId).execute(); seems to return null. I've tried it with different files, different MIME types, directly from Google Drive as well as using the Google File Picker.

I've followed the steps described over at https://developers.google.com/drive/examples/java as closely as possible.

Has anyone been able to get the sample running?

edit: Here's the log output of the FileServlet when requesting the URL /svc?file_id=0B08R9MrOE-ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw (the 404 error is thrown at line 78):

2012-04-26 08:21:36.077
com.google.api.client.http.HttpRequest execute: -------------- REQUEST  --------------
GET https://www.googleapis.com/drive/v1/files/0B08R9MrOE-ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw
Accept-Encoding: gzip
User-Agent: Google-HTTP-Java-Client/1.8.3-beta (gzip)

D 2012-04-26 08:21:36.263
com.google.api.client.http.HttpResponse <init>: -------------- RESPONSE --------------
403 OK
content-type: application/json; charset=UTF-8
content-encoding: gzip
date: Thu
date: 26 Apr 2012 06:21:36 GMT
expires: Thu
expires: 26 Apr 2012 06:21:36 GMT
cache-control: private
cache-control: max-age=0
x-content-type-options: nosniff
x-frame-options: SAMEORIGIN
x-xss-protection: 1; mode=block
content-length: 188
server: GSE
x-google-cache-control: remote-fetch
via: HTTP/1.1 GWA

D 2012-04-26 08:21:36.265
com.google.api.client.http.HttpResponse getContent: Response size: 188 bytes
D 2012-04-26 08:21:36.271
com.google.api.client.http.HttpResponse getContent: {
 "error": {
  "errors": [
   {
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit Exceeded. Please sign up",
    "extendedHelp": "https://code.google.com/apis/console"
   }
  ],
  "code": 403,
  "message": "Daily Limit Exceeded. Please sign up"
 }
}

This sounds a lot like "I don't know you" to me, so I have taken another look at my Client ID and Client Secret: I've noticed that there are two Client IDs and Client Secrets being displayed in the API Console, one "Client ID for web applications" and another "Client ID for Drive SDK". I've used the one for web applications previously, so I tried to switch to the one for the Drive SDK. Unfortunately, this doesn't change anything. Same error... :/

解决方案

I eventually managed to get it working. I'm not sure what was the problem before, but here are some tips for those who are facing similar problems:

  • The "Client ID for web applications" and the "Client ID for Drive SDK" confused me. Unfortunately the documentation doesn't tell you which one to use at which place, but it seems like you only need the "Client ID for web applications".

  • If you update your Chrome extension or the API console it could take some time until Drive recognizes those changes. For example, changing the OAuth Client ID in the API console could take some time until it takes effect, since everybody's caching. If you are testing your application, deleting cache and cookies helps speed up the process.

Good luck with your applications, and thanks to everybody who helped me!

这篇关于Google Drive SDK - Java示例不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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