gpt4 book ai didi

php - 如何在 google drive v3 PHP 中更新文件

转载 作者:可可西里 更新时间:2023-11-01 12:30:11 26 4
gpt4 key购买 nike

我似乎无法使用以下代码更新谷歌驱动器中的文件,一切正常但文件保持不变?我正在使用 v3 api。

 function updateFile($service, $fileId, $data) {
try {
$emptyFile = new Google_Service_Drive_DriveFile();
$file = $service->files->get($fileId);
$service->files->update($fileId, $emptyFile, array(
'data' => $data,
'mimeType' => 'text/csv',
'uploadType' => 'multipart'
));
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
}

最佳答案

我设法做到了,你必须将空文件作为第二个参数,不知道为什么,但这篇文章对我帮助很大:Google Drive API v3 Migration

这是最终的解决方案:

function updateFile($service, $fileId, $data) {
try {
$emptyFile = new Google_Service_Drive_DriveFile();
$service->files->update($fileId, $emptyFile, array(
'data' => $data,
'mimeType' => 'text/csv',
'uploadType' => 'multipart'
));
} catch (Exception $e) {
print "An error occurred: " . $e->getMessage();
}
}

其中 $fileId 是您正在更新的文件,data 是您正在更新文件的新内容。

在此之后不要忘记刷新 google drive,因为它的预览没有改变,我为此浪费了一个小时:/。希望这会有所帮助。

关于php - 如何在 google drive v3 PHP 中更新文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35296311/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com