@IvanN777

Ккак в 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');


Беда в том, что файл закрытый, а я хотел бы разрешить просмотр всем.
Никто не сталкивался?
  • Вопрос задан
  • 324 просмотра
Пригласить эксперта
Ответы на вопрос 1
dimonchik2013
@dimonchik2013
non progredi est regredi
Ответ написан
Комментировать
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы