0

I am trying to create a PHP function that when a file path is given and also a folder name it will upload the file (99.9% of the time is video) and give me the link back.

I have managed to do all of these steps, the only problem is before going forward I noticed that I need to make the file public, also I need to wait until google drive finishes processing then proceed with the code, I am also using PHP.

any help is very much appreciated.

        $permission = new Google_Service_Drive_Permission();
        //$permission->setValue( 'me' );  //if i uncomment this i get error that method setvalue does not exist
        $permission->setRole( 'reader' );
        $permission->setType( 'anyone' );
        try {
           $a = $service->permissions->create($result->getId(), $permission);
        } catch (Exception $e) {
          print "An error occurred: " . $e->getMessage();
        }
        echo $publicOriginallink = "https://drive.google.com/file/d/".$result->getId()."/view";

even after executing this the status of the file does not change and still stays private

Uncaught Error: Call to undefined method Google_Service_Drive_Permission::setValue()

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449
  • Welcome to stack please edit your question include your code and describe any issues you are having with your current solution. – Linda Lawton - DaImTo Jan 25 '21 at 06:42
  • @DaImTo hello i have added the method i tried recebtly to try and make the file public but did not work for me – Seddek Iguijji Jan 25 '21 at 06:50
  • What was the error. – Linda Lawton - DaImTo Jan 25 '21 at 07:16
  • if i uncomment setvalue i get Fatal error: Uncaught Error: Call to undefined method Google_Service_Drive_Permission::setValue() but if i remove it goes without any error but when i check file i still find it private not public – Seddek Iguijji Jan 25 '21 at 08:00
  • Have you checked the documentation Value is not a parameter for Drive permission. How do you know the file is not public, have you tried doing a permissions.list on the file to see what was created? – Linda Lawton - DaImTo Jan 25 '21 at 08:14
  • i tried manually via another account and browser can you please let me know the correct code to make a file public for anyone with link to view via the file id ? – Seddek Iguijji Jan 25 '21 at 08:31
  • A file id can not be used in a link to a google drive file. You wold need to use the webview link in the file response. – Linda Lawton - DaImTo Jan 25 '21 at 08:37
  • i check manually by going to my google drive as for generating a link i think it is like this https://drive.google.com/file/d/idhere/view – Seddek Iguijji Jan 25 '21 at 09:04
  • A file id can not be used in a link to a google drive file. You wold need to use the webview link in the file response. do a file.get find the webviewlink – Linda Lawton - DaImTo Jan 25 '21 at 09:15
  • i have found a workaround for this by setting the parent folder to public it makes all files inside as public by default however i would still prefer enabling it myself, the last problem i have now is after uploading a video it usually goes to processing how do i know when its done via php ? – Seddek Iguijji Jan 25 '21 at 09:33
  • `If the request succeeds, the server returns the HTTP 200 OK status code along with the file's metadata` Is that what you meant? Once you get the file data, it is uploaded. – Kessy Jan 25 '21 at 11:52

0 Answers0