将Drive API中的响应正文保存到PHPword文档

时间:2015-10-27 14:38:20

标签: php codeigniter google-drive-api drive phpword

我正在开发一款应用。我一直在使用Drive API但是卡住了。从谷歌文档中检索响应正文如下:

function GetDocumentBody($file) {
    $downloadUrls =  $this->drive_services->files->get($file)->getExportLinks();
    $downloadUrl=$downloadUrls['application/pdf'];

  if ($downloadUrl) {
    $request = new Google_Http_Request($downloadUrl, 'GET', null, null);
    $httpRequest = $this->drive_services->getClient()->getAuth()->authenticatedRequest($request);
    if ($httpRequest->getResponseHttpCode() == 200) {

        //var_dump($httpRequest->getResponseBody());die();
      return $httpRequest->getResponseBody();
    } else {
      // An error occurred.
      return null;
    }
  } else {
    // The file doesn't have any content stored on Drive.
    return null;
  }

}

这是我的控制器

 function GetDocumentBody(){
    $this->cloneJob($this->driverestapis_model->downloadFile('1untELR1y30mqu61X6lHSme3VCgbaIOeF0XxMy-b0sG4'));
}

function cloneJob($data){
    // Template processor instance creation
    echo date('H:i:s'), ' Creating new TemplateProcessor instance...';
    $templateProcessor = new \PhpOffice\PhpWord\TemplateProcessor('BULK/Sample_07_TemplateCloneRow.docx');


    //data
    $templateProcessor->setValue('data',htmlspecialchars($data));

    echo date('H:i:s'), ' Saving the result document...';
    $templateProcessor->saveAs('BULK/Sample_08_TemplateCloneRow.docx');

    //echo getEndingNotes(array('Word2007' => 'docx'));
}

拉动响应体后显示

  

.PK。< [Gword /footer1.xml V N 0 Э /hU 8 x Mc ;έ C3G%克[NӘ̸f&安培; Ho'd< F#W.w

我做错了什么

0 个答案:

没有答案