简体   繁体   中英

How to create a public accessible folder in google drive through drive API?

I am creating a folder in Google Drive to upload images in it, but to access those images without any authentication I want to make folder public at the time of creating it.

But unfortunately I have not found any additional function or argument to use with this API to create a new public folder with public accessible permission .

Here is my code for creating a new folder in Drive:

$folder = new Google\Service\Drive\DriveFile();
$folder->setName("MyPublicFolder_media");
$folder->setMimeType('application/vnd.google-apps.folder');
$createdFolder = $service->files->create($folder);
$folderId = $createdFolder->getId(); 

Inside the Google Documentation shared by @ADyson, you can find a sample on how to share the file using the APIs, just change 'type': 'anyone' .

Also, I found these sample codes.

Level: Anyone with the link

$newPermission = new Google_Service_Drive_Permission();
$newPermission->setValue('default');
$newPermission->setType('anyone');
$newPermission->setRole('reader');
$newPermission->setWithLink('true');
 
$permission = $service->permissions->insert('File_ID', $newPermission );

Level: Public on the web – Anyone can find and view

$newPermission = new Google_Service_Drive_Permission();
$newPermission->setValue('default');
$newPermission->setType('anyone');
$newPermission->setRole('reader');
  
$permission = $service->permissions->insert('File_ID', $newPermission );

Or you can see the sample in this blog

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM