我正在使用此功能从Google驱动器下载文件,它工作正常,但没有下载任何文件,我还需要做其他事情吗?这是网站上的示例,并且正在与我一起工作。我在$ httpRequest-> getResponseBody()中写了一个回显。并正确打印,但是我要怎么下载呢?
$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 {
echo 'An error occurred';
exit;
return null;
}
} else {
echo'The file doesnt have any content stored on Drive';
exit;
return null;
}
答案 0 :(得分:0)
如果public Stream BuildReport(DataSet dataSet, Report report, string path, string parameters)
{
try
{
var reportDocument = new ReportDocument();
reportDocument.Load(path);
reportDocument.SetDataSource(dataSet);
AddParametersToReport(ref reportDocument, report, parameters);
// Set database credentials
reportDocument.SetDatabaseLogon("dbUsername", "dbPassword");
return ReportDocument.ExportToStream(ExportFormatType.PortableDocFormat);
}
catch(Exception ex)
{
_loggingService.FatalFormat($"Exception: {ex}");
throw;
}
}
正在打印数据,那为什么不将其保存到文件中呢?
$httpRequest->getResponseBody();
Drive v3
Google云端硬盘第3版已经推出了两年多,您应该考虑更新您的应用程序。
您应该考虑遵循Google的下载教程manage downloads
$data = $httpRequest->getResponseBody();
file_put_contents("test.txt", data);