doxd96148 2015-07-13 15:42
浏览 47
已采纳

Google_Http_Request to Google-Drive-API可获取响应正文的可读数据

Hello i am making a test request to my google drive via the php library they provide. The request is successful and the data are received but are not readable to humans.

The related document information:

MIME type: application/vnd.oasis.opendocument.text

after making a request via:

  $file = $service->files->get($fileId);
  $downloadUrl = $file->getDownloadUrl();
  if ($downloadUrl) {
    $request = new Google_Http_Request($downloadUrl, 'GET', null, null);
    $httpRequest = $service->getClient()->getAuth()->authenticatedRequest($request);
    if ($httpRequest->getResponseHttpCode() == 200) {
      return $httpRequest->getResponseBody();
    } else {
      // An error occurred.
      return NULL;
    }
   } else {
    // The file doesn't have any content stored on Drive.
    return NULL;
   }

I get the data of the document, but they look like gibberish to me. Something like :

PK%03%04%14%08%C2%B0brE%5E%C3%862%0C%27%27%08mimetypeapplication%2Fvnd.oasis.opendocument.textPK%03%04%14%08%C2%B0brE%18Configurations2%2Ffloater%2FPK%03%04%14%08%08%08%C2%B0brE%27Configurations2%2Faccelerator%2Fcurrent.xml%03PK%07%08%02PK%03%04%14%08%C2%B0brE%1FConfigurations2%2Fimages%2FBitmaps%2FPK%03%04%14%08%C2%B0brE%18Configurations2%2Fmenubar%2FPK%03%04%14%08%C2%B0brE%1CConfigurations2%2Fprogressbar%2FPK%03%04%14%08%C2%B0brE%1AConfigurations2%2Fpopupmenu%2FPK%03%04%14%08%C2%B0brE%18Configurations2%2Ftoolbar%2FPK%03%04%14%08%C2%B0brE%1AConfigurations2%2Fstatusbar%2FPK%03%04%14%08%C2%B0brE%1AConfigurations2%2Ftoolpanel%2FPK%03%04%14%08%C2%B0brE7%C5%A1%C3%BB%24%E2%80%9E!%E2%80%9E!%18Thumbnails%2Fthumbnail.png%E2%80%B0PNG%20%1A%20IHDR%C3%86%01%08%02g%3F%C5%BE%17!KIDATx%C5%93%C3%AD%5D9%E2%80%99%C3%A2L%13%C3%8D%C5%BD%C3%B8%C2%8F%E2%80%9Ad(8%C3%81p%02%C2%81%C6%92%E2%80%A6%C3%9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3%A5r%3C%060%C2%B7B%5C%3E%C3%8Cfm%C2%B6t%5BD%C2%AB%C3%AE%C3%87%CB%9C%C3%9D%C5%A0%C3%89%C3%A13%C3%9D%C3%B3%C3%9B%C3%82%C2%AF%C5%B8%3D%C2%B6%C5%BDE%C3%B8%3D%C3%897%C3%87%C3%9D!%C3%A0a%C3%8A%C3%B7%17M%C2%A9%3B%C2%A9%C3%AE!%C3%BAl%C3%AE*%3B%20%C2%BB%E2%84%A2%C2%BD%C3%B8%2F%E2%80%9A%C3%B1%C3%B7%C3%B0%C3%BF%E2%80%9DZ%C2%8FWQ%C2%8F%C3%9D%C3%94%C3%A2%C2%B0%E2%80%94K%C3%9Aa%1C%C2%B6%01%C3%B8%C3%85%E2%80%B9%E2%80%B9%5D%E2%80%A1%13H%C3%93%C2%BD%5C%C3%95%E2%80%99%C2%BB%C5%92%E2%80%94%C3%A2%C5%BD%0F%02%C2%B9%C3%A5r%C2%BD%5B%C3%84%2F%19T%C3%BA%C3%B2a%C2%B3b%17%C3%BC%C2%B3%5C%C2%B2%C3%B0X%7C%C3%A5%C3%BB%C3%A5%C3%8F%C3%8Fl%3B%5B%C2%ADA%5C%20%C3%BF%C3%A2%E2%80%A1%C3%9B%1E%C2%A4c%C3%B8YO%E2%80%A1%20V%C3%B1GU%C2%BB%3D%E2%80%BAda%3E%0F%C3%B8%C3%B3.H%C3%B7%7F%E2%82%ACo%20%C2%B3%C3%A2%E2%80%9D%14%C2%A3%C2%8Fu%7F%C3%91_%E2%80%BA%C2%90%C3%A21d%C3%9FO%C2%B3%04z%C6%92%3F%C2%AB%7B%5D%C2%B2%C3%BF%C2%A7%C3%94B%3D%60%C3%A2EV%06E

I assume setting a content type may solve this and actually get back readable information (the content of the file) that are there on this .odt file.

The general idea is to use google drive as document parser if possible, so i can work with their content.

  • 写回答

1条回答 默认 最新

  • douqi5079 2015-07-13 16:10
    关注

    You've used getDownloadUrl so what gets downloaded is exactly the same as what got uploaded. If you upload an ODT document without conversion, then when you download it you also get an ODT document.

    It sounds like what you meant to do was to upload it with convert=true so it becomes a Google Doc, and then download it using one of the exportLink properties.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?