Siedzę już przy tym kilka dni i ciągle nie wychodzi. Ktoś ma jakiś pomysł co tu jest źle? Plik chyba zostaje załadowany na serwer bo jak użyję metody $this->googleDrive->files->listFiles()->getFiles(); to widnieje na liście, ale jak zaloguję się na dysk google za pomocą przeglądarki internetowej to go tam nie ma. Nie działa też metoda emptyTrash(), umieściłem w koszu jeden plik (ręcznie po zalogowaniu na dysk z przeglądarki) i użyłem tej metody, i nic się nie stało. Nie pokazują się też żadne błędy. Używam tej biblioteki: https://packagist.org/packages/google/apiclient

  1. <?php
  2. namespace App;
  3.  
  4. use Google_Client, Google_Service_Drive, Google_Service_Drive_DriveFile;
  5.  
  6. class Cloud
  7. {
  8. private $googleDrive;
  9.  
  10. public function __construct()
  11. {
  12. putenv('GOOGLE_APPLICATION_CREDENTIALS='.DIR['APP'].'credentials.json');
  13. $googleClient = new Google_Client();
  14. $googleClient->addScope(Google_Service_Drive::DRIVE_FILE);
  15. $googleClient->addScope(Google_Service_Drive::DRIVE);
  16. $googleClient->useApplicationDefaultCredentials();
  17. $this->googleDrive = new Google_Service_Drive($googleClient);
  18.  
  19. $file = new Google_Service_Drive_DriveFile();
  20. $file->setName(uniqid().'.png');
  21. $file->setDescription('test');
  22. $file->setMimeType('image/png');
  23. $data = file_get_contents(DIR['APP'].'plik.png');
  24.  
  25. $createdFile = $this->googleDrive->files->create
  26. (
  27. $file,
  28.  
  29. [
  30. 'data' => $data,
  31. 'mimeType' => 'image/png',
  32. 'uploadType' => 'multipart'
  33. ]
  34. );
  35.  
  36. print_r($createdFile);
  37.  
  38. $this->googleDrive->files->emptyTrash();
  39. }
  40. }