Reputation: 1763
I am trying to create a new spreadsheet, which I understand is now possible in v4 of the API, but I don't see anything detailing how to create a sheet in the PHP documentation. I got:
$client->setApplicationName("Test");
$client->setScopes(['https://www.googleapis.com/auth/sheets']);
$service = new Google_Service_Sheets($client);
$service->spreadsheets->create();
But it expects parameter 1 to be an instance of Google_Service_Sheets_Spreadsheet, and I'm not sure what exactly I should provide.
Upvotes: 4
Views: 2993
Reputation: 369
You can use RestedBox to access your Google Sheets and local spreadsheet data through an API, including querying.
Upvotes: -1
Reputation: 1763
Got it figured out. The sheet was created under the service account, not the primary account. Had to use the Drive API to add permissions to share with the primary account:
$client->setScopes(
['https://www.googleapis.com/auth/spreadsheets',
'https://www.googleapis.com/auth/drive']);
$service = new Google_Service_Sheets($client);
$drive = new Google_Service_Drive($client);
$ss = $service->spreadsheets->create(new Google_Service_Sheets_Spreadsheet());
$newPermission = new Google_Service_Drive_Permission();
$newPermission->setEmailAddress("[email protected]");
$newPermission->setType('user');
$newPermission->setRole('writer');
$optParams = array('sendNotificationEmail' => false);
$drive->permissions->create($ss->spreadsheetId,$newPermission,$optParams);
Upvotes: 9