Reputation: 43
I am trying to create a blank spreadsheet inside an existing folder (i.e. inside GOOGLE_DRIVE_FOLDER_ID) but my code seems to ignore the folder ID and keeps creating the blank spreadsheet in the root of my Google Drive instead of creating the blank file inside the folder as indicated by:
$file->setParents('GOOGLE_DRIVE_FOLDER_ID');
Below is more code for context:
$client = new Google_Client();
$client->setScopes(Google_Service_Drive::DRIVE, Google_Service_Sheets::SPREADSHEETS);
...
$service = new Google_Service_Drive($client);
$file = new Google_Service_Drive_DriveFile();
$file->setParents('GOOGLE_DRIVE_FOLDER_ID');
$file->setMimeType('application/vnd.google-apps.spreadsheet');
$file->setName('Test File');
$results = $service->files->create($file);
I can't find any proper PHP code sample documentation for the Google Drive API V3. Is this possibly a permission issue?
I would love some help as I have been struggling with this code. Thanks!
Upvotes: 1
Views: 369
Reputation: 201553
I think your scopes can be used for your situation. But I think that setParents('GOOGLE_DRIVE_FOLDER_ID')
is required to be modified. parents
is 1 dimensional array. So how about modifying as follows?
$file->setParents('GOOGLE_DRIVE_FOLDER_ID');
$file->setParents(array('GOOGLE_DRIVE_FOLDER_ID'));
Upvotes: 2