无法获取谷歌实时API资源



我正在玩Google Drive API。我已经成功地进行了身份验证,并检索了文件清单和其他东西,但我的目标是为Google Drive中保存的文档编写一个可替代的(如果有限的话)编辑器。不幸的是,文档中提到的downloadUrl (https://developers.google.com/drive/v2/reference/files)不存在,只有exportLinks。为了处理Google Drive中文档的原生格式,有必要使用实时API。

很好,我试着检索文档中暗示的未记录的(但暗示的)实时资源,发现:https://www.googleapis.com/drive/v2/files/FILEID/realtime -

HTTP/1.1 400 Bad Request
Content-Type: application/json; charset=UTF-8
Date: Tue, 05 Aug 2014 03:02:51 GMT
Expires: Tue, 05 Aug 2014 03:02:51 GMT
Cache-Control: private, max-age=0
X-Content-Type-Options: nosniff
X-Frame-Options: SAMEORIGIN
X-XSS-Protection: 1; mode=block
Server: GSE
Alternate-Protocol: 443:quic
Transfer-Encoding: chunked
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "lockedDomainCreationFailure",
    "message": "The OAuth token was received in the query string, which this API forbids for response formats other than JSON or XML. If possible, try sending the OAuth token in the Authorization header instead."
   }
  ],
  "code": 400,
  "message": "The OAuth token was received in the query string, which this API forbids for response formats other than JSON or XML. If possible, try sending the OAuth token in the Authorization header instead."
 }
}

一个奇怪的错误消息。使用标头而不是access_token参数进行身份验证并不能使其工作。我使用了为实时资源找到的API资源管理器(https://developers.google.com/drive/v2/reference/realtime/get),它也不起作用。当与同一文件一起使用时,它给出以下消息:

400 Bad Request
- Hide headers -
cache-control:  private, max-age=0
content-encoding:  gzip
content-length:  123
content-type:  application/json; charset=UTF-8
date:  Tue, 05 Aug 2014 03:14:42 GMT
expires:  Tue, 05 Aug 2014 03:14:42 GMT
server:  GSE
{
 "error": {
  "errors": [
   {
    "domain": "global",
    "reason": "invalid",
    "message": "Invalid Value"
   }
  ],
  "code": 400,
  "message": "Invalid Value"
 }
}

我知道这个文件很好,因为我对它所做的其他API调用都工作了(探索注释功能和其他东西)。这是我遇到的令人沮丧的问题,但希望有人能帮助我。我希望能够以非破坏性的方式编辑基于规范浏览器的编辑器之外的协作文档!


小更新:

GET https://www.googleapis.com/drive/v2/files/1s8NArXPG0CWRHaA9HQ-zND086Uh5CoUFC2p3b3NI3Ek/realtime?key={YOUR_API_KEY}

是API资源管理器(在这里https://developers.google.com/drive/v2/reference/realtime/get找到)用来获取上面的400错误消息的URL。事实证明,我只设置了一个OAuth2客户端ID——实时API需要一个"简单API密钥"。服务器端API密钥也不能工作——它必须是Android应用程序、iOS应用程序或基于浏览器的应用程序的API密钥。这是非常不方便的,因为我对基于浏览器的任何东西都不感兴趣,但也许有一些方法可以编写一个小型托管shim来实现我的梦想。为什么你一定要这么做,谷歌?

您不能使用实时API访问现有文档。它用于创建您自己的自定义数据、协作数据模型。

最新更新