Using the latest version of PHP apis from Google (0.60), the code sample from google developer page seems to work except that the 'webViewLink' field is empty/null when using 'print_r($createdFile)' at the end of the function.
The drive.google.com site for my Google Apps domain shows the new folder successfully created with public permissions.
Any ideas?
A "few" years later here's a working sample with a service account. I have a G Suite account and in https://admin.google.com/example.com/AdminHome?chromeless=1#OGX:ManageOauthClients I have set my API client to API scope https://www.googleapis.com/auth/drive and then
include_once __DIR__ . '/../vendor/autoload.php';
$client = new Google_Client();
$client->setAuthConfig('my_auth.json');
$client->addScope('https://www.googleapis.com/auth/drive');
$client->setSubject('admin.example.com');
$service = new Google_Service_Drive($client);
$x = $service->files->listFiles([
'spaces' => 'drive', // this doesn't seem necessary
'q' => 'name = "download"',
'fields' => 'files(id, name, webViewLink, webContentLink)',
]);
Do pay attention to the fields argument: it does not retrieve anything but id and name if you leave it out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With