我有一个上传文件和下载他们与谷歌服务帐户的脚本.这看起来工作得很好,但现在下载时并非如此.当点击链接下载文件,而不是开始下载时,会出现Google Drive登录页面. 老实说,我不知道对Google Cloud配置的PHP代码进行了任何更改.我都判断过了,我看不出有什么变化或什么不对劲.我必须说我不是专家.
先谢谢你.
我已经判断了代码和Google配置.我期待着从php代码上传和下载文件到Google Drive.结果是上传文件很好,但当下载这些文件时,会出现Google Drive登录窗口,而不是下载文件.
require_once 'google-api-php-client/vendor/autoload.php';
putenv('GOOGLE_APPLICATION_CREDENTIALS=googlecredentials-path-file.json');
$client = new Google_Client();
$client->useApplicationDefaultCredentials();
$client->setScopes(['https://www.googleapis.com/auth/drive.file']);
try {
$service = new Google_Service_Drive($client);
$google_file = new Google_Service_Drive_DriveFile();
$file_path = 'buho.jpg';
$google_file->setName($file_path);
$google_file->setParents(['Google-Drive-folder-id']);
$google_file->setDescription('File uploaded from a PHP application');
$google_file->setMimeType('image/jpeg');
$result = $service->files->create(
$google_file,
array(
'data' => file_get_contents($file_path),
'mimeType' => 'image/jpeg',
'uploadType' => 'media'
)
);
echo '<a href="https://drive.google.com/open?id=' . $result->id . '" target="_blank">' . $result->name .'</a>';