【发布时间】:2012-04-25 20:52:04
【问题描述】:
我正在尝试使用官方 Java 示例熟悉 Google Drive API。但是,在浪费了几个小时并尝试设置了两次示例之后,我仍然无法按预期使用它。
它不会显示文件的内容,而是在 FileServlet(/svc 路径)中引发 404 错误。更具体地说,service.files().get(fileId).execute(); 似乎返回 null。我已经直接从 Google Drive 以及使用 Google File Picker 尝试了不同的文件、不同的 MIME 类型。
我已尽可能严格地遵循https://developers.google.com/drive/examples/java 中描述的步骤。
有人能够让示例运行吗?
编辑:
以下是请求 URL /svc?file_id=0B08R9MrOE-ejZTY2M2I5MjAtYmVjZS00OTkyLWI4ZTEtOTg4OGM3YTIxMWEw 时 FileServlet 的日志输出(第 78 行抛出 404 错误):
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"
}
}
这听起来很像“我不认识你”,所以我再次查看了我的客户端 ID 和客户端密码:我注意到有两个客户端 ID 和客户端密码显示在API 控制台、一个“Web 应用程序的客户端 ID”和另一个“Drive SDK 的客户端 ID”。我以前用过那个用于 Web 应用程序,所以我尝试切换到用于 Drive SDK 的那个。不幸的是,这并没有改变任何东西。同样的错误...:/
【问题讨论】:
-
您能否更改logging.properties 以记录有关 API 请求的更多详细信息并向我们显示响应正文?
-
FWIW,我编写了该示例及其指南。你能给我一个产生 404 的确切行号吗?针对 /svc 请求的 URL 是什么? GET /svc 需要 file_id 参数。
-
@VicFryzel,谢谢大家!我已经用日志输出更新了帖子。
标签: java google-drive-api