【发布时间】:2016-07-15 16:45:47
【问题描述】:
我是谷歌 API 的新手。我的目标是将文档(doc,docx)从服务器上传到谷歌驱动器,而无需任何客户端批准过程。上传后,我想将其导出为 pdf 文件。
我创建了一个服务帐户。上传本身工作正常。可以下载上传的文件。当我尝试从驱动器中导出文档时,出现以下错误。
{
"error": {
"errors": [
{
"domain": "global",
"reason": "badRequest",
"message": "ExportonlysupportsGoogleDocs."
}
],
"code": 400,
"message": "ExportonlysupportsGoogleDocs."
}
}
我使用 google drive api v2 php 库。这是我用于导出的代码。
$tempUrl = "https://www.googleapis.com/drive/v2/files/xxxx/export?mimeType=application%2Fpdf";
$request = new Google_Http_Request($tempUrl, 'GET', null, null);
$httpRequest = $service->getClient()->getAuth()->authenticatedRequest($request);
if ($httpRequest->getResponseHttpCode() == 200) {
$newFile = 'downLoaded.pdf';
file_put_contents($newFile, $httpRequest->getResponseBody());
} else {
var_dump($httpRequest->getResponseBody());
}
不能从谷歌驱动器导出吗? 'ExportonlysupportsGoogleDocs.' 是什么意思?方法?我错过了什么?
感谢您的关注,欢迎提出任何意见。
【问题讨论】:
标签: php google-drive-api export pdf-generation