Answer the question
In order to leave comments, you need to log in
How to make a file public in google drive api?
<?php
require __DIR__ . '/vendor/autoload.php';
class UploadPresentation
{
public function execute($filePath, $title)
{
$client = $this->getClient();
$driveService = new \Google_Service_Drive($client);
//$fileId = $this->uploadFile($driveService, $filePath, $title);
$fileId = '1ZhBOGeLYLZS5gFsMNf-OoiDSrxIF23ilFXEKKRdpAWw';
$file = $driveService->files->get($fileId, array("fields"=>"webViewLink"));
print($file->webViewLink);
}
private function getClient()
{
$client = new \Google_Client();
$client->setApplicationName('My PHP App');
$client->setScopes([\Google_Service_Drive::DRIVE]);
$client->setAccessType('offline');
$jsonAuth = file_get_contents('credentials.json');
$client->setAuthConfig(json_decode($jsonAuth, true));
return $client;
}
private function uploadFile(Google_Service_Drive $driveService, $filePath, $title)
{
$date = new \DateTime();
$timestamp = $date->getTimestamp();
$timestamp = '1';
$file = new \Google_Service_Drive_DriveFile([
'name' => $title.$timestamp,
'mimeType' => 'application/vnd.google-apps.presentation'
]);
$params = [
'uploadType' => 'multipart',
'data' => file_get_contents($filePath),
'mimeType' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
];
$upload = $driveService->files->create($file, $params);
$fileId = $upload->id;
return $fileId;
}
}
$upload = new \UploadPresentation();
$upload->execute('/home/ivan/1_projects/drive/test.pptx', 'test');
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question